protobuf-core 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +18 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +23 -0
  8. data/Rakefile +5 -0
  9. data/bin/protoc-gen-ruby +16 -0
  10. data/lib/protobuf.rb +27 -0
  11. data/lib/protobuf/code_generator.rb +44 -0
  12. data/lib/protobuf/core.rb +2 -0
  13. data/lib/protobuf/core/version.rb +5 -0
  14. data/lib/protobuf/decoder.rb +73 -0
  15. data/lib/protobuf/deprecation.rb +112 -0
  16. data/lib/protobuf/descriptors.rb +3 -0
  17. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +54 -0
  18. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +251 -0
  19. data/lib/protobuf/encoder.rb +67 -0
  20. data/lib/protobuf/enum.rb +303 -0
  21. data/lib/protobuf/exceptions.rb +9 -0
  22. data/lib/protobuf/field.rb +74 -0
  23. data/lib/protobuf/field/base_field.rb +267 -0
  24. data/lib/protobuf/field/bool_field.rb +59 -0
  25. data/lib/protobuf/field/bytes_field.rb +82 -0
  26. data/lib/protobuf/field/double_field.rb +25 -0
  27. data/lib/protobuf/field/enum_field.rb +68 -0
  28. data/lib/protobuf/field/field_array.rb +87 -0
  29. data/lib/protobuf/field/fixed32_field.rb +25 -0
  30. data/lib/protobuf/field/fixed64_field.rb +28 -0
  31. data/lib/protobuf/field/float_field.rb +41 -0
  32. data/lib/protobuf/field/int32_field.rb +21 -0
  33. data/lib/protobuf/field/int64_field.rb +21 -0
  34. data/lib/protobuf/field/integer_field.rb +23 -0
  35. data/lib/protobuf/field/message_field.rb +65 -0
  36. data/lib/protobuf/field/sfixed32_field.rb +27 -0
  37. data/lib/protobuf/field/sfixed64_field.rb +28 -0
  38. data/lib/protobuf/field/signed_integer_field.rb +29 -0
  39. data/lib/protobuf/field/sint32_field.rb +21 -0
  40. data/lib/protobuf/field/sint64_field.rb +21 -0
  41. data/lib/protobuf/field/string_field.rb +34 -0
  42. data/lib/protobuf/field/uint32_field.rb +21 -0
  43. data/lib/protobuf/field/uint64_field.rb +21 -0
  44. data/lib/protobuf/field/varint_field.rb +73 -0
  45. data/lib/protobuf/generators/base.rb +70 -0
  46. data/lib/protobuf/generators/enum_generator.rb +41 -0
  47. data/lib/protobuf/generators/extension_generator.rb +27 -0
  48. data/lib/protobuf/generators/field_generator.rb +131 -0
  49. data/lib/protobuf/generators/file_generator.rb +132 -0
  50. data/lib/protobuf/generators/group_generator.rb +105 -0
  51. data/lib/protobuf/generators/message_generator.rb +98 -0
  52. data/lib/protobuf/generators/printable.rb +160 -0
  53. data/lib/protobuf/logging.rb +39 -0
  54. data/lib/protobuf/message.rb +193 -0
  55. data/lib/protobuf/message/fields.rb +133 -0
  56. data/lib/protobuf/message/serialization.rb +89 -0
  57. data/lib/protobuf/optionable.rb +23 -0
  58. data/lib/protobuf/wire_type.rb +10 -0
  59. data/proto/dynamic_discovery.proto +44 -0
  60. data/proto/google/protobuf/compiler/plugin.proto +147 -0
  61. data/proto/google/protobuf/descriptor.proto +620 -0
  62. data/proto/rpc.proto +62 -0
  63. data/protobuf-core.gemspec +31 -0
  64. data/spec/bin/protoc-gen-ruby_spec.rb +23 -0
  65. data/spec/data/data.bin +3 -0
  66. data/spec/data/types.bin +0 -0
  67. data/spec/encoding/all_types_spec.rb +105 -0
  68. data/spec/encoding/extreme_values_spec.rb +0 -0
  69. data/spec/functional/class_inheritance_spec.rb +52 -0
  70. data/spec/functional/compile_and_require_spec.rb +29 -0
  71. data/spec/lib/protobuf/base_spec.rb +84 -0
  72. data/spec/lib/protobuf/code_generator_spec.rb +60 -0
  73. data/spec/lib/protobuf/enum_generator_spec.rb +73 -0
  74. data/spec/lib/protobuf/enum_spec.rb +265 -0
  75. data/spec/lib/protobuf/extension_generator_spec.rb +42 -0
  76. data/spec/lib/protobuf/field/bool_field_spec.rb +51 -0
  77. data/spec/lib/protobuf/field/field_array_spec.rb +69 -0
  78. data/spec/lib/protobuf/field/float_field_spec.rb +55 -0
  79. data/spec/lib/protobuf/field/int32_field_spec.rb +90 -0
  80. data/spec/lib/protobuf/field/string_field_spec.rb +45 -0
  81. data/spec/lib/protobuf/field_generator_spec.rb +102 -0
  82. data/spec/lib/protobuf/field_spec.rb +191 -0
  83. data/spec/lib/protobuf/file_generator_spec.rb +32 -0
  84. data/spec/lib/protobuf/message_generator_spec.rb +0 -0
  85. data/spec/lib/protobuf/message_spec.rb +526 -0
  86. data/spec/lib/protobuf/optionable_spec.rb +46 -0
  87. data/spec/lib/protobuf_spec.rb +45 -0
  88. data/spec/spec_helper.rb +9 -0
  89. data/spec/support/packed_field.rb +22 -0
  90. data/spec/support/test/all_types.data.bin +0 -0
  91. data/spec/support/test/all_types.data.txt +119 -0
  92. data/spec/support/test/bacon.proto +14 -0
  93. data/spec/support/test/defaults.pb.rb +27 -0
  94. data/spec/support/test/defaults.proto +9 -0
  95. data/spec/support/test/enum.pb.rb +61 -0
  96. data/spec/support/test/enum.proto +34 -0
  97. data/spec/support/test/extended.pb.rb +24 -0
  98. data/spec/support/test/extended.proto +10 -0
  99. data/spec/support/test/extreme_values.data.bin +0 -0
  100. data/spec/support/test/google_unittest.pb.rb +530 -0
  101. data/spec/support/test/google_unittest.proto +713 -0
  102. data/spec/support/test/google_unittest_import.pb.rb +39 -0
  103. data/spec/support/test/google_unittest_import.proto +64 -0
  104. data/spec/support/test/google_unittest_import_public.pb.rb +10 -0
  105. data/spec/support/test/google_unittest_import_public.proto +38 -0
  106. data/spec/support/test/multi_field_extensions.pb.rb +58 -0
  107. data/spec/support/test/multi_field_extensions.proto +33 -0
  108. data/spec/support/test/resource.pb.rb +106 -0
  109. data/spec/support/test/resource.proto +94 -0
  110. metadata +306 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 83c7505aba93f4c033ae5d944de90257b1637e5c
4
+ data.tar.gz: 2ef322c2803330111a37e4a2c1a6b381e5ce7d18
5
+ SHA512:
6
+ metadata.gz: a695b42270eb555cdbb7d780f8e42dd2dcdc48baafc918817a39f8c8bc49e56c117a68bb61ad0ca5db898cfbf853bf5c31c7a365de85ddd3e25a12344c8848f5
7
+ data.tar.gz: 4eced497a030f9207600d081e99222d778a39fdd772623722e1c94e663ec62ba5c9ae071d12d424b7f07d5ee0b0759e2ec4f58bfb542ffbf85c1a2827c425457
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /spec/support/test/bacon.pb.rb
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,18 @@
1
+ language: ruby
2
+ before_install:
3
+ - gem install bundler --no-doc
4
+ - sudo apt-get update -qq
5
+ - sudo apt-get install -y protobuf-compiler
6
+ cache: bundler
7
+ rvm:
8
+ - 1.9
9
+ - 2.0
10
+ - 2.1
11
+ - 2.2
12
+ - jruby
13
+ - jruby-head
14
+ - rbx-2
15
+ matrix:
16
+ allow_failures:
17
+ - rvm: rbx-2
18
+ - rvm: jruby-head
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in protobuf-core.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Michael Ries
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ [![Build Status](https://travis-ci.org/ruby-protobuf/protobuf-core.svg?branch=master)](https://travis-ci.org/ruby-protobuf/protobuf-core)
2
+
3
+ # Protobuf::Core
4
+
5
+ This is an implemention of [Google's protocol buffers](http://code.google.com/p/protobuf) in pure ruby. It supports 2.5.0 currently.
6
+
7
+ This core gem supports the basics of:
8
+
9
+ * compiling `.proto` files into `.pb.rb` files
10
+ * encoding messages
11
+ * decoding messages
12
+
13
+ If all you need is the ability to convert binary protobuf messages into ruby objects, then this gem will fit the bill.
14
+
15
+ Extension gems to this gem add on the ability to run an RPC server and exchange messages over raw TCP sockets or [ZeroMQ](http://zeromq.org/).
16
+
17
+ ## Contributing
18
+
19
+ 1. Fork it ( https://github.com/[my-github-username]/protobuf-core/fork )
20
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
21
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
22
+ 4. Push to the branch (`git push origin my-new-feature`)
23
+ 5. Create a new Pull Request
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Before requiring protobuf, ensure that we will not load any
4
+ # server or client code.
5
+ #
6
+ ENV['PB_NO_NETWORKING'] = '1'
7
+
8
+ $LOAD_PATH << ::File.expand_path("../../lib", __FILE__)
9
+ require 'protobuf'
10
+ require 'protobuf/descriptors'
11
+ require 'protobuf/code_generator'
12
+
13
+ request_bytes = STDIN.read
14
+ code_generator = ::Protobuf::CodeGenerator.new(request_bytes)
15
+ response_bytes = code_generator.response_bytes
16
+ STDOUT.print(response_bytes)
@@ -0,0 +1,27 @@
1
+ require 'logger'
2
+ require 'pp'
3
+ require 'stringio'
4
+
5
+ require 'active_support/core_ext/object/blank'
6
+ require 'active_support/core_ext/object/try'
7
+ require 'active_support/inflector'
8
+ require 'active_support/json'
9
+ require 'active_support/notifications'
10
+
11
+ require 'protobuf/deprecation'
12
+
13
+ module Protobuf
14
+ # Permit unknown field on Message initialization
15
+ #
16
+ # Default: true
17
+ #
18
+ # Simple boolean to define whether we want to permit unknown fields
19
+ # on Message intialization; otherwise a ::Protobuf::FieldNotDefinedError is thrown.
20
+ def self.ignore_unknown_fields?
21
+ !defined?(@ignore_unknown_fields) || @ignore_unknown_fields
22
+ end
23
+
24
+ def self.ignore_unknown_fields=(value)
25
+ @ignore_unknown_fields = !!value
26
+ end
27
+ end
@@ -0,0 +1,44 @@
1
+ require 'protobuf/generators/file_generator'
2
+
3
+ module Protobuf
4
+ class CodeGenerator
5
+
6
+ CodeGeneratorFatalError = Class.new(RuntimeError)
7
+
8
+ def self.fatal(message)
9
+ fail CodeGeneratorFatalError, message
10
+ end
11
+
12
+ def self.print_tag_warning_suppress
13
+ STDERR.puts "Suppress tag warning output with PB_NO_TAG_WARNINGS=1."
14
+ def self.print_tag_warning_suppress; end
15
+ end
16
+
17
+ def self.warn(message)
18
+ STDERR.puts("[WARN] #{message}")
19
+ end
20
+
21
+ private
22
+
23
+ attr_accessor :request
24
+
25
+ public
26
+
27
+ def initialize(request_bytes)
28
+ self.request = ::Google::Protobuf::Compiler::CodeGeneratorRequest.decode(request_bytes)
29
+ end
30
+
31
+ def generate_file(file_descriptor)
32
+ ::Protobuf::Generators::FileGenerator.new(file_descriptor).generate_output_file
33
+ end
34
+
35
+ def response_bytes
36
+ generated_files = request.proto_file.map do |file_descriptor|
37
+ generate_file(file_descriptor)
38
+ end
39
+
40
+ ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => generated_files)
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,2 @@
1
+ require "protobuf/core/version"
2
+ require "protobuf"
@@ -0,0 +1,5 @@
1
+ module Protobuf
2
+ module Core
3
+ VERSION = "3.5.0"
4
+ end
5
+ end
@@ -0,0 +1,73 @@
1
+ require 'protobuf/wire_type'
2
+ require 'protobuf/exceptions'
3
+
4
+ module Protobuf
5
+ class Decoder
6
+
7
+ # Read bytes from +stream+ and pass to +message+ object.
8
+ def self.decode_each_field(stream, &block)
9
+ until stream.eof?
10
+ tag, bytes = read_field(stream)
11
+ block.call(tag, bytes)
12
+ end
13
+ end
14
+
15
+ def self.read_field(stream)
16
+ tag, wire_type = read_key(stream)
17
+ bytes = case wire_type
18
+ when ::Protobuf::WireType::VARINT then
19
+ read_varint(stream)
20
+ when ::Protobuf::WireType::FIXED64 then
21
+ read_fixed64(stream)
22
+ when ::Protobuf::WireType::LENGTH_DELIMITED then
23
+ read_length_delimited(stream)
24
+ when ::Protobuf::WireType::FIXED32 then
25
+ read_fixed32(stream)
26
+ when ::Protobuf::WireType::START_GROUP then
27
+ fail NotImplementedError, 'Group is deprecated.'
28
+ when ::Protobuf::WireType::END_GROUP then
29
+ fail NotImplementedError, 'Group is deprecated.'
30
+ else
31
+ fail InvalidWireType, wire_type
32
+ end
33
+
34
+ [tag, bytes]
35
+ end
36
+
37
+ # Read 32-bit string value from +stream+.
38
+ def self.read_fixed32(stream)
39
+ stream.read(4)
40
+ end
41
+
42
+ # Read 64-bit string value from +stream+.
43
+ def self.read_fixed64(stream)
44
+ stream.read(8)
45
+ end
46
+
47
+ # Read key pair (tag and wire-type) from +stream+.
48
+ def self.read_key(stream)
49
+ bits = read_varint(stream)
50
+ wire_type = bits & 0x07
51
+ tag = bits >> 3
52
+ [tag, wire_type]
53
+ end
54
+
55
+ # Read length-delimited string value from +stream+.
56
+ def self.read_length_delimited(stream)
57
+ value_length = read_varint(stream)
58
+ stream.read(value_length)
59
+ end
60
+
61
+ # Read varint integer value from +stream+.
62
+ def self.read_varint(stream)
63
+ value = index = 0
64
+ begin
65
+ byte = stream.readbyte
66
+ value |= (byte & 0x7f) << (7 * index)
67
+ index += 1
68
+ end while (byte & 0x80).nonzero?
69
+ value
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,112 @@
1
+ require 'active_support/deprecation'
2
+
3
+ module Protobuf
4
+ if ::ActiveSupport::Deprecation.is_a?(Class)
5
+ class DeprecationBase < ::ActiveSupport::Deprecation
6
+ def deprecate_methods(*args)
7
+ deprecation_options = { :deprecator => self }
8
+
9
+ if args.last.is_a?(Hash)
10
+ args.last.merge!(deprecation_options)
11
+ else
12
+ args.push(deprecation_options)
13
+ end
14
+
15
+ super
16
+ end
17
+ end
18
+
19
+ class Deprecation < DeprecationBase
20
+ def define_deprecated_methods(target_module, method_hash)
21
+ target_module.module_eval do
22
+ method_hash.each do |old_method, new_method|
23
+ alias_method old_method, new_method
24
+ end
25
+ end
26
+
27
+ deprecate_methods(target_module, method_hash)
28
+ end
29
+ end
30
+
31
+ class FieldDeprecation < DeprecationBase
32
+ # this is a convenience deprecator for deprecated proto fields
33
+
34
+ def deprecate_method(target_module, method_name)
35
+ deprecate_methods(target_module, method_name => target_module)
36
+ end
37
+
38
+ private
39
+
40
+ def deprecated_method_warning(method_name, target_module)
41
+ "#{target_module.name}##{method_name} field usage is deprecated"
42
+ end
43
+ end
44
+ else
45
+ # TODO: remove this clause when Rails < 4 support is no longer needed
46
+ deprecator = ::ActiveSupport::Deprecation.clone
47
+ deprecator.instance_eval do
48
+ def new(deprecation_horizon = nil, *)
49
+ self.deprecation_horizon = deprecation_horizon if deprecation_horizon
50
+ self
51
+ end
52
+ end
53
+ Deprecation = deprecator.clone
54
+ FieldDeprecation = deprecator.clone
55
+
56
+ Deprecation.instance_eval do
57
+ def define_deprecated_methods(target_module, method_hash)
58
+ target_module.module_eval do
59
+ method_hash.each do |old_method, new_method|
60
+ alias_method old_method, new_method
61
+ end
62
+ end
63
+
64
+ deprecate_methods(target_module, method_hash)
65
+ end
66
+ end
67
+
68
+ FieldDeprecation.instance_eval do
69
+ def deprecate_method(target_module, method_name)
70
+ deprecate_methods(target_module, method_name => target_module)
71
+ end
72
+
73
+ private
74
+
75
+ def deprecated_method_warning(method_name, target_module)
76
+ "#{target_module.name}##{method_name} field usage is deprecated"
77
+ end
78
+ end
79
+ end
80
+
81
+ def self.deprecator
82
+ @deprecator ||= Deprecation.new('4.0', to_s).tap do |deprecation|
83
+ deprecation.silenced = ENV.key?('PB_IGNORE_DEPRECATIONS')
84
+ deprecation.behavior = :stderr
85
+ end
86
+ end
87
+
88
+ def self.field_deprecator
89
+ @field_deprecator ||= FieldDeprecation.new.tap do |deprecation|
90
+ deprecation.silenced = ENV.key?('PB_IGNORE_DEPRECATIONS')
91
+ deprecation.behavior = :stderr
92
+ end
93
+ end
94
+
95
+ # Print Deprecation Warnings
96
+ #
97
+ # Default: true
98
+ #
99
+ # Simple boolean to define whether we want field deprecation warnings to
100
+ # be printed to stderr or not. The rpc_server has an option to set this value
101
+ # explicitly, or you can turn this option off by setting
102
+ # ENV['PB_IGNORE_DEPRECATIONS'] to a non-empty value.
103
+ #
104
+ # The rpc_server option will override the ENV setting.
105
+ def self.print_deprecation_warnings?
106
+ !field_deprecator.silenced
107
+ end
108
+
109
+ def self.print_deprecation_warnings=(value)
110
+ field_deprecator.silenced = !value
111
+ end
112
+ end
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH << ::File.expand_path("../descriptors", __FILE__)
2
+ require 'google/protobuf/descriptor.pb'
3
+ require 'google/protobuf/compiler/plugin.pb'
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # This file is auto-generated. DO NOT EDIT!
5
+ #
6
+ require 'protobuf/message'
7
+
8
+
9
+ ##
10
+ # Imports
11
+ #
12
+ require 'google/protobuf/descriptor.pb'
13
+
14
+ module Google
15
+ module Protobuf
16
+ module Compiler
17
+
18
+ ##
19
+ # Message Classes
20
+ #
21
+ class CodeGeneratorRequest < ::Protobuf::Message; end
22
+ class CodeGeneratorResponse < ::Protobuf::Message
23
+ class File < ::Protobuf::Message; end
24
+
25
+ end
26
+
27
+
28
+
29
+ ##
30
+ # Message Fields
31
+ #
32
+ class CodeGeneratorRequest
33
+ repeated :string, :file_to_generate, 1
34
+ optional :string, :parameter, 2
35
+ repeated ::Google::Protobuf::FileDescriptorProto, :proto_file, 15
36
+ end
37
+
38
+ class CodeGeneratorResponse
39
+ class File
40
+ optional :string, :name, 1
41
+ optional :string, :insertion_point, 2
42
+ optional :string, :content, 15
43
+ end
44
+
45
+ optional :string, :error, 1
46
+ repeated ::Google::Protobuf::Compiler::CodeGeneratorResponse::File, :file, 15
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+