protobuffy 3.6.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +67 -0
  4. data/.rubocop_todo.yml +145 -0
  5. data/.travis.yml +25 -5
  6. data/CHANGES.md +55 -0
  7. data/CONTRIBUTING.md +1 -1
  8. data/LICENSE.txt +17 -9
  9. data/README.md +13 -12
  10. data/Rakefile +15 -11
  11. data/bin/protoc-gen-ruby +8 -3
  12. data/bin/rpc_server +1 -0
  13. data/examples/lib/example/reverse-client.rb +2 -2
  14. data/install-protobuf.sh +28 -0
  15. data/lib/protobuf.rb +57 -53
  16. data/lib/protobuf/cli.rb +94 -74
  17. data/lib/protobuf/code_generator.rb +60 -9
  18. data/lib/protobuf/decoder.rb +19 -65
  19. data/lib/protobuf/deprecation.rb +117 -0
  20. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +11 -1
  21. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +55 -3
  22. data/lib/protobuf/encoder.rb +13 -53
  23. data/lib/protobuf/enum.rb +58 -63
  24. data/lib/protobuf/field.rb +4 -4
  25. data/lib/protobuf/field/base_field.rb +101 -173
  26. data/lib/protobuf/field/bool_field.rb +17 -11
  27. data/lib/protobuf/field/bytes_field.rb +21 -35
  28. data/lib/protobuf/field/double_field.rb +0 -1
  29. data/lib/protobuf/field/enum_field.rb +23 -22
  30. data/lib/protobuf/field/field_array.rb +5 -4
  31. data/lib/protobuf/field/fixed32_field.rb +1 -1
  32. data/lib/protobuf/field/fixed64_field.rb +0 -1
  33. data/lib/protobuf/field/float_field.rb +4 -1
  34. data/lib/protobuf/field/int32_field.rb +0 -1
  35. data/lib/protobuf/field/int64_field.rb +0 -1
  36. data/lib/protobuf/field/integer_field.rb +0 -1
  37. data/lib/protobuf/field/message_field.rb +13 -28
  38. data/lib/protobuf/field/sfixed32_field.rb +0 -1
  39. data/lib/protobuf/field/sfixed64_field.rb +0 -1
  40. data/lib/protobuf/field/signed_integer_field.rb +0 -1
  41. data/lib/protobuf/field/sint32_field.rb +0 -1
  42. data/lib/protobuf/field/sint64_field.rb +0 -1
  43. data/lib/protobuf/field/string_field.rb +2 -4
  44. data/lib/protobuf/field/uint32_field.rb +0 -1
  45. data/lib/protobuf/field/uint64_field.rb +0 -1
  46. data/lib/protobuf/field/varint_field.rb +30 -13
  47. data/lib/protobuf/generators/base.rb +30 -16
  48. data/lib/protobuf/generators/enum_generator.rb +6 -9
  49. data/lib/protobuf/generators/extension_generator.rb +1 -2
  50. data/lib/protobuf/generators/field_generator.rb +25 -13
  51. data/lib/protobuf/generators/file_generator.rb +157 -35
  52. data/lib/protobuf/generators/group_generator.rb +22 -17
  53. data/lib/protobuf/generators/message_generator.rb +13 -14
  54. data/lib/protobuf/generators/option_generator.rb +17 -0
  55. data/lib/protobuf/generators/printable.rb +12 -13
  56. data/lib/protobuf/generators/service_generator.rb +2 -3
  57. data/lib/protobuf/http.rb +2 -2
  58. data/lib/protobuf/lifecycle.rb +20 -33
  59. data/lib/protobuf/logging.rb +39 -0
  60. data/lib/protobuf/message.rb +114 -47
  61. data/lib/protobuf/message/fields.rb +170 -88
  62. data/lib/protobuf/message/serialization.rb +19 -18
  63. data/lib/protobuf/optionable.rb +53 -6
  64. data/lib/protobuf/rpc/buffer.rb +18 -19
  65. data/lib/protobuf/rpc/client.rb +22 -50
  66. data/lib/protobuf/rpc/connectors/base.rb +177 -12
  67. data/lib/protobuf/rpc/connectors/http.rb +14 -9
  68. data/lib/protobuf/rpc/connectors/ping.rb +89 -0
  69. data/lib/protobuf/rpc/connectors/socket.rb +13 -8
  70. data/lib/protobuf/rpc/connectors/zmq.rb +178 -73
  71. data/lib/protobuf/rpc/dynamic_discovery.pb.rb +4 -1
  72. data/lib/protobuf/rpc/env.rb +12 -12
  73. data/lib/protobuf/rpc/error.rb +3 -3
  74. data/lib/protobuf/rpc/error/client_error.rb +4 -4
  75. data/lib/protobuf/rpc/error/server_error.rb +9 -9
  76. data/lib/protobuf/rpc/middleware/exception_handler.rb +6 -2
  77. data/lib/protobuf/rpc/middleware/logger.rb +8 -4
  78. data/lib/protobuf/rpc/middleware/request_decoder.rb +17 -21
  79. data/lib/protobuf/rpc/middleware/response_encoder.rb +22 -27
  80. data/lib/protobuf/rpc/middleware/statsd.rb +3 -3
  81. data/lib/protobuf/rpc/rpc.pb.rb +4 -1
  82. data/lib/protobuf/rpc/server.rb +1 -1
  83. data/lib/protobuf/rpc/servers/http/server.rb +19 -17
  84. data/lib/protobuf/rpc/servers/socket/server.rb +78 -70
  85. data/lib/protobuf/rpc/servers/socket/worker.rb +4 -4
  86. data/lib/protobuf/rpc/servers/socket_runner.rb +27 -15
  87. data/lib/protobuf/rpc/servers/zmq/broker.rb +70 -31
  88. data/lib/protobuf/rpc/servers/zmq/server.rb +55 -47
  89. data/lib/protobuf/rpc/servers/zmq/util.rb +14 -13
  90. data/lib/protobuf/rpc/servers/zmq/worker.rb +16 -16
  91. data/lib/protobuf/rpc/servers/zmq_runner.rb +26 -7
  92. data/lib/protobuf/rpc/service.rb +21 -27
  93. data/lib/protobuf/rpc/service_directory.rb +43 -27
  94. data/lib/protobuf/rpc/service_dispatcher.rb +9 -10
  95. data/lib/protobuf/rpc/service_filters.rb +32 -55
  96. data/lib/protobuf/rpc/stat.rb +4 -8
  97. data/lib/protobuf/socket.rb +1 -2
  98. data/lib/protobuf/tasks/compile.rake +3 -4
  99. data/lib/protobuf/varint.rb +9 -0
  100. data/lib/protobuf/varint_pure.rb +13 -0
  101. data/lib/protobuf/version.rb +1 -1
  102. data/lib/protobuf/zmq.rb +2 -2
  103. data/proto/google/protobuf/descriptor.proto +190 -31
  104. data/protobuffy.gemspec +30 -17
  105. data/spec/benchmark/tasks.rb +27 -19
  106. data/spec/bin/protoc-gen-ruby_spec.rb +11 -6
  107. data/spec/encoding/all_types_spec.rb +96 -84
  108. data/spec/encoding/extreme_values_spec.rb +0 -0
  109. data/spec/functional/class_inheritance_spec.rb +52 -0
  110. data/spec/functional/code_generator_spec.rb +38 -0
  111. data/spec/functional/socket_server_spec.rb +15 -15
  112. data/spec/functional/zmq_server_spec.rb +29 -27
  113. data/spec/lib/protobuf/cli_spec.rb +82 -67
  114. data/spec/lib/protobuf/code_generator_spec.rb +37 -10
  115. data/spec/lib/protobuf/enum_spec.rb +77 -46
  116. data/spec/lib/protobuf/field/bool_field_spec.rb +91 -0
  117. data/spec/lib/protobuf/field/double_field_spec.rb +9 -0
  118. data/spec/lib/protobuf/field/enum_field_spec.rb +26 -0
  119. data/spec/lib/protobuf/field/field_array_spec.rb +69 -0
  120. data/spec/lib/protobuf/field/fixed32_field_spec.rb +7 -0
  121. data/spec/lib/protobuf/field/fixed64_field_spec.rb +7 -0
  122. data/spec/lib/protobuf/field/float_field_spec.rb +90 -0
  123. data/spec/lib/protobuf/field/int32_field_spec.rb +114 -1
  124. data/spec/lib/protobuf/field/int64_field_spec.rb +7 -0
  125. data/spec/lib/protobuf/field/message_field_spec.rb +132 -0
  126. data/spec/lib/protobuf/field/sfixed32_field_spec.rb +9 -0
  127. data/spec/lib/protobuf/field/sfixed64_field_spec.rb +9 -0
  128. data/spec/lib/protobuf/field/sint32_field_spec.rb +9 -0
  129. data/spec/lib/protobuf/field/sint64_field_spec.rb +9 -0
  130. data/spec/lib/protobuf/field/string_field_spec.rb +44 -11
  131. data/spec/lib/protobuf/field/uint32_field_spec.rb +7 -0
  132. data/spec/lib/protobuf/field/uint64_field_spec.rb +7 -0
  133. data/spec/lib/protobuf/field_spec.rb +4 -6
  134. data/spec/lib/protobuf/generators/base_spec.rb +80 -13
  135. data/spec/lib/protobuf/generators/enum_generator_spec.rb +35 -21
  136. data/spec/lib/protobuf/generators/extension_generator_spec.rb +12 -13
  137. data/spec/lib/protobuf/generators/field_generator_spec.rb +73 -21
  138. data/spec/lib/protobuf/generators/file_generator_spec.rb +89 -6
  139. data/spec/lib/protobuf/generators/service_generator_spec.rb +25 -13
  140. data/spec/lib/protobuf/lifecycle_spec.rb +25 -20
  141. data/spec/lib/protobuf/message_spec.rb +578 -79
  142. data/spec/lib/protobuf/optionable_spec.rb +202 -26
  143. data/spec/lib/protobuf/rpc/client_spec.rb +16 -16
  144. data/spec/lib/protobuf/rpc/connectors/base_spec.rb +167 -13
  145. data/spec/lib/protobuf/rpc/connectors/connector_spec.rb +4 -5
  146. data/spec/lib/protobuf/rpc/connectors/http_spec.rb +13 -11
  147. data/spec/lib/protobuf/rpc/connectors/ping_spec.rb +69 -0
  148. data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +6 -7
  149. data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +35 -52
  150. data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +10 -10
  151. data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +11 -11
  152. data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +23 -23
  153. data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +11 -11
  154. data/spec/lib/protobuf/rpc/middleware/statsd_spec.rb +6 -6
  155. data/spec/lib/protobuf/rpc/servers/http/server_spec.rb +47 -44
  156. data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +6 -6
  157. data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +12 -10
  158. data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +11 -11
  159. data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +7 -7
  160. data/spec/lib/protobuf/rpc/service_directory_spec.rb +47 -49
  161. data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +8 -25
  162. data/spec/lib/protobuf/rpc/service_filters_spec.rb +102 -69
  163. data/spec/lib/protobuf/rpc/service_spec.rb +37 -36
  164. data/spec/lib/protobuf/rpc/stat_spec.rb +7 -9
  165. data/spec/lib/protobuf/varint_spec.rb +29 -0
  166. data/spec/lib/protobuf_spec.rb +55 -28
  167. data/spec/spec_helper.rb +12 -27
  168. data/spec/support/all.rb +0 -1
  169. data/spec/support/packed_field.rb +4 -3
  170. data/spec/support/{test → protos}/all_types.data.bin +0 -0
  171. data/spec/support/{test → protos}/all_types.data.txt +0 -0
  172. data/spec/support/{test → protos}/enum.pb.rb +8 -4
  173. data/spec/support/{test → protos}/enum.proto +4 -1
  174. data/spec/support/{test → protos}/extreme_values.data.bin +0 -0
  175. data/spec/support/protos/google_unittest.bin +0 -0
  176. data/spec/support/protos/google_unittest.pb.rb +798 -0
  177. data/spec/support/{test → protos}/google_unittest.proto +237 -66
  178. data/spec/support/protos/google_unittest_custom_options.bin +0 -0
  179. data/spec/support/protos/google_unittest_custom_options.pb.rb +268 -0
  180. data/spec/support/protos/google_unittest_custom_options.proto +424 -0
  181. data/spec/support/protos/google_unittest_import.pb.rb +55 -0
  182. data/spec/support/{test → protos}/google_unittest_import.proto +19 -10
  183. data/spec/support/protos/google_unittest_import_public.pb.rb +31 -0
  184. data/spec/support/{test → protos}/google_unittest_import_public.proto +8 -5
  185. data/spec/support/{test → protos}/multi_field_extensions.pb.rb +5 -2
  186. data/spec/support/{test → protos}/multi_field_extensions.proto +2 -0
  187. data/spec/support/{test → protos}/resource.pb.rb +47 -11
  188. data/spec/support/{test → protos}/resource.proto +24 -1
  189. data/spec/support/resource_service.rb +23 -0
  190. data/spec/support/server.rb +32 -61
  191. metadata +119 -59
  192. data/lib/protobuf/deprecator.rb +0 -42
  193. data/lib/protobuf/logger.rb +0 -93
  194. data/lib/protobuf/rpc/connector.rb +0 -21
  195. data/lib/protobuf/rpc/connectors/common.rb +0 -172
  196. data/spec/data/data.bin +0 -3
  197. data/spec/data/types.bin +0 -0
  198. data/spec/lib/protobuf/logger_spec.rb +0 -145
  199. data/spec/lib/protobuf/rpc/connector_spec.rb +0 -26
  200. data/spec/lib/protobuf/rpc/connectors/common_spec.rb +0 -170
  201. data/spec/support/test/defaults.pb.rb +0 -25
  202. data/spec/support/test/defaults.proto +0 -9
  203. data/spec/support/test/extended.pb.rb +0 -22
  204. data/spec/support/test/extended.proto +0 -10
  205. data/spec/support/test/google_unittest.pb.rb +0 -543
  206. data/spec/support/test/google_unittest_import.pb.rb +0 -37
  207. data/spec/support/test/google_unittest_import_public.pb.rb +0 -8
  208. data/spec/support/test/resource_service.rb +0 -26
  209. data/spec/support/tolerance_matcher.rb +0 -40
@@ -15,8 +15,7 @@
15
15
  # gem 'protobuf', :require => 'protobuf/socket'
16
16
  #
17
17
  require 'protobuf'
18
- ::Protobuf.connector_type = :socket
19
-
20
18
  require 'protobuf/rpc/servers/socket/server'
21
19
  require 'protobuf/rpc/connectors/socket'
22
20
 
21
+ ::Protobuf.connector_type_class = ::Protobuf::Rpc::Connectors::Socket
@@ -3,7 +3,7 @@ require 'fileutils'
3
3
  namespace :protobuf do
4
4
 
5
5
  desc 'Clean & Compile the protobuf source to ruby classes. Pass PB_NO_CLEAN=1 if you do not want to force-clean first.'
6
- task :compile, [ :package, :source, :destination, :plugin, :file_extension ] do |tasks, args|
6
+ task :compile, [:package, :source, :destination, :plugin, :file_extension] do |_tasks, args|
7
7
  args.with_defaults(:destination => 'lib')
8
8
  args.with_defaults(:source => 'definitions')
9
9
  args.with_defaults(:plugin => 'ruby')
@@ -18,8 +18,7 @@ namespace :protobuf do
18
18
  command << "protoc"
19
19
  command << "--#{args[:plugin]}_out=#{args[:destination]}"
20
20
  command << "-I #{args[:source]}"
21
- command << "#{args[:source]}/#{args[:package]}/*.proto"
22
- command << "#{args[:source]}/#{args[:package]}/**/*.proto"
21
+ command << Dir["#{args[:source]}/#{args[:package]}/**/*.proto"].join(" ")
23
22
  full_command = command.join(' ')
24
23
 
25
24
  puts full_command
@@ -27,7 +26,7 @@ namespace :protobuf do
27
26
  end
28
27
 
29
28
  desc 'Clean the generated *.pb.rb files from the destination package. Pass PB_FORCE_CLEAN=1 to skip confirmation step.'
30
- task :clean, [ :package, :destination, :file_extension ] do |task, args|
29
+ task :clean, [:package, :destination, :file_extension] do |_task, args|
31
30
  args.with_defaults(:destination => 'lib')
32
31
  args.with_defaults(:file_extension => '.pb.rb')
33
32
 
@@ -0,0 +1,9 @@
1
+ module Protobuf
2
+ class Varint
3
+ if defined?(::Varint)
4
+ extend ::Varint
5
+ else
6
+ extend VarintPure
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module Protobuf
2
+ module VarintPure
3
+ def decode(stream)
4
+ value = index = 0
5
+ begin
6
+ byte = stream.readbyte
7
+ value |= (byte & 0x7f) << (7 * index)
8
+ index += 1
9
+ end while (byte & 0x80).nonzero?
10
+ value
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module Protobuf
2
- VERSION = '3.6.0'
2
+ VERSION = '4.0.0'.freeze
3
3
  end
data/lib/protobuf/zmq.rb CHANGED
@@ -14,8 +14,8 @@
14
14
  # gem 'protobuf', :require => 'protobuf/zmq'
15
15
  #
16
16
  require 'protobuf'
17
- Protobuf.connector_type = :zmq
18
-
19
17
  require 'ffi-rzmq'
20
18
  require 'protobuf/rpc/servers/zmq/server'
21
19
  require 'protobuf/rpc/connectors/zmq'
20
+
21
+ Protobuf.connector_type_class = ::Protobuf::Rpc::Connectors::Zmq
@@ -1,6 +1,6 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2008 Google Inc. All rights reserved.
3
- // http://code.google.com/p/protobuf/
3
+ // https://developers.google.com/protocol-buffers/
4
4
  //
5
5
  // Redistribution and use in source and binary forms, with or without
6
6
  // modification, are permitted provided that the following conditions are
@@ -37,10 +37,14 @@
37
37
  // without any other information (e.g. without reading its imports).
38
38
 
39
39
 
40
+ syntax = "proto2";
40
41
 
41
42
  package google.protobuf;
43
+ option go_package = "descriptor";
42
44
  option java_package = "com.google.protobuf";
43
45
  option java_outer_classname = "DescriptorProtos";
46
+ option csharp_namespace = "Google.Protobuf.Reflection";
47
+ option objc_class_prefix = "GPB";
44
48
 
45
49
  // descriptor.proto must be optimized for speed because reflection-based
46
50
  // algorithms don't work during bootstrapping.
@@ -74,10 +78,14 @@ message FileDescriptorProto {
74
78
  optional FileOptions options = 8;
75
79
 
76
80
  // This field contains optional information about the original source code.
77
- // You may safely remove this entire field whithout harming runtime
81
+ // You may safely remove this entire field without harming runtime
78
82
  // functionality of the descriptors -- the information is needed only by
79
83
  // development tools.
80
84
  optional SourceCodeInfo source_code_info = 9;
85
+
86
+ // The syntax of the proto file.
87
+ // The supported values are "proto2" and "proto3".
88
+ optional string syntax = 12;
81
89
  }
82
90
 
83
91
  // Describes a message type.
@@ -96,7 +104,21 @@ message DescriptorProto {
96
104
  }
97
105
  repeated ExtensionRange extension_range = 5;
98
106
 
107
+ repeated OneofDescriptorProto oneof_decl = 8;
108
+
99
109
  optional MessageOptions options = 7;
110
+
111
+ // Range of reserved tag numbers. Reserved tag numbers may not be used by
112
+ // fields or extension ranges in the same message. Reserved ranges may
113
+ // not overlap.
114
+ message ReservedRange {
115
+ optional int32 start = 1; // Inclusive.
116
+ optional int32 end = 2; // Exclusive.
117
+ }
118
+ repeated ReservedRange reserved_range = 9;
119
+ // Reserved field names, which may not be used by fields in the same message.
120
+ // A given name may only be reserved once.
121
+ repeated string reserved_name = 10;
100
122
  }
101
123
 
102
124
  // Describes a field within a message.
@@ -143,7 +165,7 @@ message FieldDescriptorProto {
143
165
  optional Label label = 4;
144
166
 
145
167
  // If type_name is set, this need not be set. If both this and type_name
146
- // are set, this must be either TYPE_ENUM or TYPE_MESSAGE.
168
+ // are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.
147
169
  optional Type type = 5;
148
170
 
149
171
  // For message and enum types, this is the name of the type. If the name
@@ -164,9 +186,24 @@ message FieldDescriptorProto {
164
186
  // TODO(kenton): Base-64 encode?
165
187
  optional string default_value = 7;
166
188
 
189
+ // If set, gives the index of a oneof in the containing type's oneof_decl
190
+ // list. This field is a member of that oneof.
191
+ optional int32 oneof_index = 9;
192
+
193
+ // JSON name of this field. The value is set by protocol compiler. If the
194
+ // user has set a "json_name" option on this field, that option's value
195
+ // will be used. Otherwise, it's deduced from the field's name by converting
196
+ // it to camelCase.
197
+ optional string json_name = 10;
198
+
167
199
  optional FieldOptions options = 8;
168
200
  }
169
201
 
202
+ // Describes a oneof.
203
+ message OneofDescriptorProto {
204
+ optional string name = 1;
205
+ }
206
+
170
207
  // Describes an enum type.
171
208
  message EnumDescriptorProto {
172
209
  optional string name = 1;
@@ -202,6 +239,11 @@ message MethodDescriptorProto {
202
239
  optional string output_type = 3;
203
240
 
204
241
  optional MethodOptions options = 4;
242
+
243
+ // Identifies if client streams multiple client messages
244
+ optional bool client_streaming = 5 [default=false];
245
+ // Identifies if server streams multiple server messages
246
+ optional bool server_streaming = 6 [default=false];
205
247
  }
206
248
 
207
249
 
@@ -228,12 +270,12 @@ message MethodDescriptorProto {
228
270
  // * For options which will be published and used publicly by multiple
229
271
  // independent entities, e-mail protobuf-global-extension-registry@google.com
230
272
  // to reserve extension numbers. Simply provide your project name (e.g.
231
- // Object-C plugin) and your porject website (if available) -- there's no need
232
- // to explain how you intend to use them. Usually you only need one extension
233
- // number. You can declare multiple options with only one extension number by
234
- // putting them in a sub-message. See the Custom Options section of the docs
235
- // for examples:
236
- // http://code.google.com/apis/protocolbuffers/docs/proto.html#options
273
+ // Objective-C plugin) and your project website (if available) -- there's no
274
+ // need to explain how you intend to use them. Usually you only need one
275
+ // extension number. You can declare multiple options with only one extension
276
+ // number by putting them in a sub-message. See the Custom Options section of
277
+ // the docs for examples:
278
+ // https://developers.google.com/protocol-buffers/docs/proto#options
237
279
  // If this turns out to be popular, a web service will be set up
238
280
  // to automatically assign option numbers.
239
281
 
@@ -263,11 +305,28 @@ message FileOptions {
263
305
  optional bool java_multiple_files = 10 [default=false];
264
306
 
265
307
  // If set true, then the Java code generator will generate equals() and
266
- // hashCode() methods for all messages defined in the .proto file. This is
267
- // purely a speed optimization, as the AbstractMessage base class includes
268
- // reflection-based implementations of these methods.
308
+ // hashCode() methods for all messages defined in the .proto file.
309
+ // This increases generated code size, potentially substantially for large
310
+ // protos, which may harm a memory-constrained application.
311
+ // - In the full runtime this is a speed optimization, as the
312
+ // AbstractMessage base class includes reflection-based implementations of
313
+ // these methods.
314
+ // - In the lite runtime, setting this option changes the semantics of
315
+ // equals() and hashCode() to more closely match those of the full runtime;
316
+ // the generated methods compute their results based on field values rather
317
+ // than object identity. (Implementations should not assume that hashcodes
318
+ // will be consistent across runtimes or versions of the protocol compiler.)
269
319
  optional bool java_generate_equals_and_hash = 20 [default=false];
270
320
 
321
+ // If set true, then the Java2 code generator will generate code that
322
+ // throws an exception whenever an attempt is made to assign a non-UTF-8
323
+ // byte sequence to a string field.
324
+ // Message reflection will do the same.
325
+ // However, an extension field still accepts non-UTF-8 byte sequences.
326
+ // This option has no effect on when used with the lite runtime.
327
+ optional bool java_string_check_utf8 = 27 [default=false];
328
+
329
+
271
330
  // Generated classes can be optimized for speed or code size.
272
331
  enum OptimizeMode {
273
332
  SPEED = 1; // Generate complete code for parsing, serialization,
@@ -278,7 +337,10 @@ message FileOptions {
278
337
  optional OptimizeMode optimize_for = 9 [default=SPEED];
279
338
 
280
339
  // Sets the Go package where structs generated from this .proto will be
281
- // placed. There is no default.
340
+ // placed. If omitted, the Go package will be derived from the following:
341
+ // - The basename of the package import path, if provided.
342
+ // - Otherwise, the package statement in the .proto file, if present.
343
+ // - Otherwise, the basename of the .proto file, without extension.
282
344
  optional string go_package = 11;
283
345
 
284
346
 
@@ -287,7 +349,7 @@ message FileOptions {
287
349
  // are not specific to any particular RPC system. They are generated by the
288
350
  // main code generators in each language (without additional plugins).
289
351
  // Generic services were the only kind of service generation supported by
290
- // early versions of proto2.
352
+ // early versions of google.protobuf.
291
353
  //
292
354
  // Generic services are now considered deprecated in favor of using plugins
293
355
  // that generate code specific to your particular RPC system. Therefore,
@@ -297,6 +359,28 @@ message FileOptions {
297
359
  optional bool java_generic_services = 17 [default=false];
298
360
  optional bool py_generic_services = 18 [default=false];
299
361
 
362
+ // Is this file deprecated?
363
+ // Depending on the target platform, this can emit Deprecated annotations
364
+ // for everything in the file, or it will be completely ignored; in the very
365
+ // least, this is a formalization for deprecating files.
366
+ optional bool deprecated = 23 [default=false];
367
+
368
+ // Enables the use of arenas for the proto messages in this file. This applies
369
+ // only to generated classes for C++.
370
+ optional bool cc_enable_arenas = 31 [default=false];
371
+
372
+
373
+ // Sets the objective c class prefix which is prepended to all objective c
374
+ // generated classes from this .proto. There is no default.
375
+ optional string objc_class_prefix = 36;
376
+
377
+ // Namespace for generated classes; defaults to the package.
378
+ optional string csharp_namespace = 37;
379
+
380
+ // Whether the nano proto compiler should generate in the deprecated non-nano
381
+ // suffixed package.
382
+ optional bool javanano_use_deprecated_package = 38;
383
+
300
384
  // The parser stores options it doesn't recognize here. See above.
301
385
  repeated UninterpretedOption uninterpreted_option = 999;
302
386
 
@@ -330,6 +414,35 @@ message MessageOptions {
330
414
  // from proto1 easier; new code should avoid fields named "descriptor".
331
415
  optional bool no_standard_descriptor_accessor = 2 [default=false];
332
416
 
417
+ // Is this message deprecated?
418
+ // Depending on the target platform, this can emit Deprecated annotations
419
+ // for the message, or it will be completely ignored; in the very least,
420
+ // this is a formalization for deprecating messages.
421
+ optional bool deprecated = 3 [default=false];
422
+
423
+ // Whether the message is an automatically generated map entry type for the
424
+ // maps field.
425
+ //
426
+ // For maps fields:
427
+ // map<KeyType, ValueType> map_field = 1;
428
+ // The parsed descriptor looks like:
429
+ // message MapFieldEntry {
430
+ // option map_entry = true;
431
+ // optional KeyType key = 1;
432
+ // optional ValueType value = 2;
433
+ // }
434
+ // repeated MapFieldEntry map_field = 1;
435
+ //
436
+ // Implementations may choose not to generate the map_entry=true message, but
437
+ // use a native map in the target language to hold the keys and values.
438
+ // The reflection APIs in such implementions still need to work as
439
+ // if the field is a repeated message field.
440
+ //
441
+ // NOTE: Do not set the option in .proto files. Always use the maps syntax
442
+ // instead. The option should only be implicitly set by the proto compiler
443
+ // parser.
444
+ optional bool map_entry = 7;
445
+
333
446
  // The parser stores options it doesn't recognize here. See above.
334
447
  repeated UninterpretedOption uninterpreted_option = 999;
335
448
 
@@ -354,10 +467,31 @@ message FieldOptions {
354
467
  // The packed option can be enabled for repeated primitive fields to enable
355
468
  // a more efficient representation on the wire. Rather than repeatedly
356
469
  // writing the tag and type for each element, the entire array is encoded as
357
- // a single length-delimited blob.
470
+ // a single length-delimited blob. In proto3, only explicit setting it to
471
+ // false will avoid using packed encoding.
358
472
  optional bool packed = 2;
359
473
 
360
474
 
475
+ // The jstype option determines the JavaScript type used for values of the
476
+ // field. The option is permitted only for 64 bit integral and fixed types
477
+ // (int64, uint64, sint64, fixed64, sfixed64). By default these types are
478
+ // represented as JavaScript strings. This avoids loss of precision that can
479
+ // happen when a large value is converted to a floating point JavaScript
480
+ // numbers. Specifying JS_NUMBER for the jstype causes the generated
481
+ // JavaScript code to use the JavaScript "number" type instead of strings.
482
+ // This option is an enum to permit additional types to be added,
483
+ // e.g. goog.math.Integer.
484
+ optional JSType jstype = 6 [default = JS_NORMAL];
485
+ enum JSType {
486
+ // Use the default type.
487
+ JS_NORMAL = 0;
488
+
489
+ // Use JavaScript strings.
490
+ JS_STRING = 1;
491
+
492
+ // Use JavaScript numbers.
493
+ JS_NUMBER = 2;
494
+ }
361
495
 
362
496
  // Should this field be parsed lazily? Lazy applies only to message-type
363
497
  // fields. It means that when the outer message is initially parsed, the
@@ -395,23 +529,10 @@ message FieldOptions {
395
529
  // is a formalization for deprecating fields.
396
530
  optional bool deprecated = 3 [default=false];
397
531
 
398
- // EXPERIMENTAL. DO NOT USE.
399
- // For "map" fields, the name of the field in the enclosed type that
400
- // is the key for this map. For example, suppose we have:
401
- // message Item {
402
- // required string name = 1;
403
- // required string value = 2;
404
- // }
405
- // message Config {
406
- // repeated Item items = 1 [experimental_map_key="name"];
407
- // }
408
- // In this situation, the map key for Item will be set to "name".
409
- // TODO: Fully-implement this, then remove the "experimental_" prefix.
410
- optional string experimental_map_key = 9;
411
-
412
532
  // For Google-internal migration only. Do not use.
413
533
  optional bool weak = 10 [default=false];
414
534
 
535
+
415
536
  // The parser stores options it doesn't recognize here. See above.
416
537
  repeated UninterpretedOption uninterpreted_option = 999;
417
538
 
@@ -421,9 +542,15 @@ message FieldOptions {
421
542
 
422
543
  message EnumOptions {
423
544
 
424
- // Set this option to false to disallow mapping different tag names to a same
545
+ // Set this option to true to allow mapping different tag names to the same
425
546
  // value.
426
- optional bool allow_alias = 2 [default=true];
547
+ optional bool allow_alias = 2;
548
+
549
+ // Is this enum deprecated?
550
+ // Depending on the target platform, this can emit Deprecated annotations
551
+ // for the enum, or it will be completely ignored; in the very least, this
552
+ // is a formalization for deprecating enums.
553
+ optional bool deprecated = 3 [default=false];
427
554
 
428
555
  // The parser stores options it doesn't recognize here. See above.
429
556
  repeated UninterpretedOption uninterpreted_option = 999;
@@ -433,6 +560,12 @@ message EnumOptions {
433
560
  }
434
561
 
435
562
  message EnumValueOptions {
563
+ // Is this enum value deprecated?
564
+ // Depending on the target platform, this can emit Deprecated annotations
565
+ // for the enum value, or it will be completely ignored; in the very least,
566
+ // this is a formalization for deprecating enum values.
567
+ optional bool deprecated = 1 [default=false];
568
+
436
569
  // The parser stores options it doesn't recognize here. See above.
437
570
  repeated UninterpretedOption uninterpreted_option = 999;
438
571
 
@@ -447,6 +580,12 @@ message ServiceOptions {
447
580
  // we were already using them long before we decided to release Protocol
448
581
  // Buffers.
449
582
 
583
+ // Is this service deprecated?
584
+ // Depending on the target platform, this can emit Deprecated annotations
585
+ // for the service, or it will be completely ignored; in the very least,
586
+ // this is a formalization for deprecating services.
587
+ optional bool deprecated = 33 [default=false];
588
+
450
589
  // The parser stores options it doesn't recognize here. See above.
451
590
  repeated UninterpretedOption uninterpreted_option = 999;
452
591
 
@@ -461,6 +600,12 @@ message MethodOptions {
461
600
  // we were already using them long before we decided to release Protocol
462
601
  // Buffers.
463
602
 
603
+ // Is this method deprecated?
604
+ // Depending on the target platform, this can emit Deprecated annotations
605
+ // for the method, or it will be completely ignored; in the very least,
606
+ // this is a formalization for deprecating methods.
607
+ optional bool deprecated = 33 [default=false];
608
+
464
609
  // The parser stores options it doesn't recognize here. See above.
465
610
  repeated UninterpretedOption uninterpreted_option = 999;
466
611
 
@@ -587,6 +732,11 @@ message SourceCodeInfo {
587
732
  // A series of line comments appearing on consecutive lines, with no other
588
733
  // tokens appearing on those lines, will be treated as a single comment.
589
734
  //
735
+ // leading_detached_comments will keep paragraphs of comments that appear
736
+ // before (but not connected to) the current element. Each paragraph,
737
+ // separated by empty lines, will be one comment element in the repeated
738
+ // field.
739
+ //
590
740
  // Only the comment content is provided; comment markers (e.g. //) are
591
741
  // stripped out. For block comments, leading whitespace and an asterisk
592
742
  // will be stripped from the beginning of each line other than the first.
@@ -607,6 +757,12 @@ message SourceCodeInfo {
607
757
  // // Another line attached to qux.
608
758
  // optional double qux = 4;
609
759
  //
760
+ // // Detached comment for corge. This is not leading or trailing comments
761
+ // // to qux or corge because there are blank lines separating it from
762
+ // // both.
763
+ //
764
+ // // Detached comment for corge paragraph 2.
765
+ //
610
766
  // optional string corge = 5;
611
767
  // /* Block comment attached
612
768
  // * to corge. Leading asterisks
@@ -614,7 +770,10 @@ message SourceCodeInfo {
614
770
  // /* Block comment attached to
615
771
  // * grault. */
616
772
  // optional int32 grault = 6;
773
+ //
774
+ // // ignored detached comments.
617
775
  optional string leading_comments = 3;
618
776
  optional string trailing_comments = 4;
777
+ repeated string leading_detached_comments = 6;
619
778
  }
620
779
  }