ruby-protocol-buffers 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -5
- data/.travis.yml +20 -0
- data/Gemfile +5 -1
- data/Gemfile.no_varint +4 -0
- data/README.md +7 -0
- data/Rakefile +3 -18
- data/lib/protocol_buffers.rb +3 -3
- data/lib/protocol_buffers/compiler.rb +7 -0
- data/lib/protocol_buffers/compiler/descriptor.pb.rb +63 -30
- data/lib/protocol_buffers/compiler/descriptor.proto +252 -25
- data/lib/protocol_buffers/compiler/file_descriptor_to_ruby.rb +7 -1
- data/lib/protocol_buffers/runtime/decoder.rb +18 -2
- data/lib/protocol_buffers/runtime/encoder.rb +17 -2
- data/lib/protocol_buffers/runtime/field.rb +14 -3
- data/lib/protocol_buffers/runtime/varint.rb +42 -36
- data/lib/protocol_buffers/version.rb +3 -0
- data/ruby-protocol-buffers.gemspec +22 -21
- data/spec/compiler_spec.rb +22 -0
- data/spec/fields_spec.rb +54 -16
- data/spec/proto_files/featureful.pb.rb +76 -0
- data/spec/proto_files/packed.pb.rb +37 -0
- data/spec/proto_files/packed.proto +30 -0
- data/spec/proto_files/simple.pb.rb +23 -0
- data/spec/runtime_spec.rb +211 -164
- data/spec/spec_helper.rb +24 -7
- data/tasks/rspec.rake +7 -0
- data/tasks/yard.rake +6 -0
- metadata +34 -6
- data/VERSION +0 -1
- data/ext/extconf.disabled.rb +0 -3
- data/ext/varint.c +0 -65
data/.gitignore
CHANGED
data/.travis.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
language: ruby
|
2
|
+
gemfile:
|
3
|
+
- Gemfile
|
4
|
+
# i can't find a way to use the same Gemfile and just specify --without varint
|
5
|
+
- Gemfile.no_varint
|
6
|
+
rvm:
|
7
|
+
- "1.8.7"
|
8
|
+
- "1.9.3"
|
9
|
+
- "2.0.0"
|
10
|
+
- jruby-18mode # JRuby in 1.8 mode
|
11
|
+
- jruby-19mode # JRuby in 1.9 mode
|
12
|
+
- rbx-18mode
|
13
|
+
- rbx-19mode
|
14
|
+
matrix:
|
15
|
+
exclude:
|
16
|
+
# can't use the varint extension in jruby runs
|
17
|
+
- rvm: jruby-18mode
|
18
|
+
gemfile: Gemfile
|
19
|
+
- rvm: jruby-19mode
|
20
|
+
gemfile: Gemfile
|
data/Gemfile
CHANGED
data/Gemfile.no_varint
ADDED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Ruby Protocol Buffers
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/codekitchen/ruby-protocol-buffers.png?branch=master)](https://travis-ci.org/codekitchen/ruby-protocol-buffers)
|
4
|
+
|
3
5
|
Protocol Buffers are a way of encoding structured data in an efficient yet
|
4
6
|
extensible format. Google uses Protocol Buffers for almost all of its internal
|
5
7
|
RPC protocols and file formats.
|
@@ -29,6 +31,11 @@ If you want to compile .proto files to ruby, you'll need `protoc` version >= 2.2
|
|
29
31
|
installed in the environment where you will be compiling them.
|
30
32
|
You do not need `protoc` installed to use the generated `.pb.rb` files.
|
31
33
|
|
34
|
+
For greater performance, consider installing the varint gem as well.
|
35
|
+
This optional gem builds a small C extension to make parsing protocol buffers
|
36
|
+
faster. If your application uses a Gemfile, add varint to the Gemfile
|
37
|
+
alongside ruby-protocol-buffers.
|
38
|
+
|
32
39
|
## Example
|
33
40
|
|
34
41
|
Given the file test.proto:
|
data/Rakefile
CHANGED
@@ -1,20 +1,5 @@
|
|
1
|
-
require
|
2
|
-
Bundler::GemHelper.install_tasks
|
1
|
+
require "bundler/gem_tasks"
|
3
2
|
|
4
|
-
|
3
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
5
4
|
|
6
|
-
|
7
|
-
RSpec::Core::RakeTask.new(:spec) do |t|
|
8
|
-
t.rspec_opts = "-c -f d"
|
9
|
-
end
|
10
|
-
RSpec::Core::RakeTask.new(:rcov) do |t|
|
11
|
-
t.rspec_opts = "-c -f d"
|
12
|
-
t.rcov = true
|
13
|
-
t.rcov_opts = ["--exclude", "spec,gems/,rubygems/"]
|
14
|
-
end
|
15
|
-
|
16
|
-
require 'yard'
|
17
|
-
YARD::Rake::YardocTask.new(:doc) do |t|
|
18
|
-
version = ProtocolBuffers::VERSION
|
19
|
-
t.options = ["--title", "ruby protocol buffers #{version}", "--files", "LICENSE,Changelog.md"]
|
20
|
-
end
|
5
|
+
task :default => [:spec]
|
data/lib/protocol_buffers.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
|
2
|
-
VERSION = File.read(File.join(File.dirname(__FILE__), "..", "VERSION")).chomp
|
1
|
+
require 'stringio'
|
3
2
|
|
4
|
-
|
3
|
+
module ProtocolBuffers
|
5
4
|
# for 1.9.2 compatibility
|
6
5
|
def self.bin_sio(*args)
|
7
6
|
sio = StringIO.new(*args)
|
@@ -10,4 +9,5 @@ module ProtocolBuffers
|
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
12
|
+
require 'protocol_buffers/version'
|
13
13
|
require 'protocol_buffers/runtime/message'
|
@@ -52,5 +52,12 @@ module ProtocolBuffers
|
|
52
52
|
(opts[:include_dirs] ||= []) << File.dirname(tempfile.path)
|
53
53
|
compile_and_load(tempfile.path, opts)
|
54
54
|
end
|
55
|
+
|
56
|
+
def self.available?
|
57
|
+
version = `protoc --version`.match(/[\d\.]+/)
|
58
|
+
version && version[0] >= "2.2"
|
59
|
+
rescue Errno::ENOENT
|
60
|
+
false
|
61
|
+
end
|
55
62
|
end
|
56
63
|
end
|
@@ -1,25 +1,26 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
3
3
|
|
4
|
-
require 'protocol_buffers
|
4
|
+
require 'protocol_buffers'
|
5
5
|
|
6
6
|
# forward declarations
|
7
|
-
class
|
8
|
-
class
|
9
|
-
class
|
10
|
-
class
|
11
|
-
class
|
12
|
-
class
|
13
|
-
class
|
14
|
-
class
|
15
|
-
class
|
16
|
-
class
|
17
|
-
class
|
18
|
-
class
|
19
|
-
class
|
20
|
-
class
|
21
|
-
class
|
22
|
-
class
|
7
|
+
class FileDescriptorSet < ::ProtocolBuffers::Message; end
|
8
|
+
class FileDescriptorProto < ::ProtocolBuffers::Message; end
|
9
|
+
class DescriptorProto < ::ProtocolBuffers::Message; end
|
10
|
+
class FieldDescriptorProto < ::ProtocolBuffers::Message; end
|
11
|
+
class EnumDescriptorProto < ::ProtocolBuffers::Message; end
|
12
|
+
class EnumValueDescriptorProto < ::ProtocolBuffers::Message; end
|
13
|
+
class ServiceDescriptorProto < ::ProtocolBuffers::Message; end
|
14
|
+
class MethodDescriptorProto < ::ProtocolBuffers::Message; end
|
15
|
+
class FileOptions < ::ProtocolBuffers::Message; end
|
16
|
+
class MessageOptions < ::ProtocolBuffers::Message; end
|
17
|
+
class FieldOptions < ::ProtocolBuffers::Message; end
|
18
|
+
class EnumOptions < ::ProtocolBuffers::Message; end
|
19
|
+
class EnumValueOptions < ::ProtocolBuffers::Message; end
|
20
|
+
class ServiceOptions < ::ProtocolBuffers::Message; end
|
21
|
+
class MethodOptions < ::ProtocolBuffers::Message; end
|
22
|
+
class UninterpretedOption < ::ProtocolBuffers::Message; end
|
23
|
+
class SourceCodeInfo < ::ProtocolBuffers::Message; end
|
23
24
|
|
24
25
|
class FileDescriptorSet < ::ProtocolBuffers::Message
|
25
26
|
repeated ::FileDescriptorProto, :file, 1
|
@@ -29,20 +30,23 @@ end
|
|
29
30
|
|
30
31
|
class FileDescriptorProto < ::ProtocolBuffers::Message
|
31
32
|
optional :string, :name, 1
|
32
|
-
optional :string, :
|
33
|
+
optional :string, :package, 2
|
33
34
|
repeated :string, :dependency, 3
|
35
|
+
repeated :int32, :public_dependency, 10
|
36
|
+
repeated :int32, :weak_dependency, 11
|
34
37
|
repeated ::DescriptorProto, :message_type, 4
|
35
38
|
repeated ::EnumDescriptorProto, :enum_type, 5
|
36
|
-
repeated ::ServiceDescriptorProto, :
|
39
|
+
repeated ::ServiceDescriptorProto, :service, 6
|
37
40
|
repeated ::FieldDescriptorProto, :extension, 7
|
38
41
|
optional ::FileOptions, :options, 8
|
42
|
+
optional ::SourceCodeInfo, :source_code_info, 9
|
39
43
|
|
40
44
|
gen_methods! # new fields ignored after this point
|
41
45
|
end
|
42
46
|
|
43
47
|
class DescriptorProto < ::ProtocolBuffers::Message
|
44
48
|
# forward declarations
|
45
|
-
class
|
49
|
+
class ExtensionRange < ::ProtocolBuffers::Message; end
|
46
50
|
|
47
51
|
# nested messages
|
48
52
|
class ExtensionRange < ::ProtocolBuffers::Message
|
@@ -65,10 +69,8 @@ end
|
|
65
69
|
|
66
70
|
class FieldDescriptorProto < ::ProtocolBuffers::Message
|
67
71
|
# forward declarations
|
68
|
-
module ::Type; end
|
69
|
-
module ::Label; end
|
70
72
|
|
71
|
-
#
|
73
|
+
# enums
|
72
74
|
module Type
|
73
75
|
include ::ProtocolBuffers::Enum
|
74
76
|
TYPE_DOUBLE = 1
|
@@ -145,19 +147,24 @@ end
|
|
145
147
|
|
146
148
|
class FileOptions < ::ProtocolBuffers::Message
|
147
149
|
# forward declarations
|
148
|
-
module ::OptimizeMode; end
|
149
150
|
|
150
|
-
#
|
151
|
+
# enums
|
151
152
|
module OptimizeMode
|
152
153
|
include ::ProtocolBuffers::Enum
|
153
154
|
SPEED = 1
|
154
155
|
CODE_SIZE = 2
|
156
|
+
LITE_RUNTIME = 3
|
155
157
|
end
|
156
158
|
|
157
159
|
optional :string, :java_package, 1
|
158
160
|
optional :string, :java_outer_classname, 8
|
159
161
|
optional :bool, :java_multiple_files, 10, :default => false
|
160
|
-
optional
|
162
|
+
optional :bool, :java_generate_equals_and_hash, 20, :default => false
|
163
|
+
optional ::FileOptions::OptimizeMode, :optimize_for, 9, :default => ::FileOptions::OptimizeMode::SPEED
|
164
|
+
optional :string, :go_package, 11
|
165
|
+
optional :bool, :cc_generic_services, 16, :default => false
|
166
|
+
optional :bool, :java_generic_services, 17, :default => false
|
167
|
+
optional :bool, :py_generic_services, 18, :default => false
|
161
168
|
repeated ::UninterpretedOption, :uninterpreted_option, 999
|
162
169
|
|
163
170
|
gen_methods! # new fields ignored after this point
|
@@ -165,6 +172,7 @@ end
|
|
165
172
|
|
166
173
|
class MessageOptions < ::ProtocolBuffers::Message
|
167
174
|
optional :bool, :message_set_wire_format, 1, :default => false
|
175
|
+
optional :bool, :no_standard_descriptor_accessor, 2, :default => false
|
168
176
|
repeated ::UninterpretedOption, :uninterpreted_option, 999
|
169
177
|
|
170
178
|
gen_methods! # new fields ignored after this point
|
@@ -172,23 +180,28 @@ end
|
|
172
180
|
|
173
181
|
class FieldOptions < ::ProtocolBuffers::Message
|
174
182
|
# forward declarations
|
175
|
-
module ::CType; end
|
176
183
|
|
177
|
-
#
|
184
|
+
# enums
|
178
185
|
module CType
|
179
186
|
include ::ProtocolBuffers::Enum
|
187
|
+
STRING = 0
|
180
188
|
CORD = 1
|
181
189
|
STRING_PIECE = 2
|
182
190
|
end
|
183
191
|
|
184
|
-
optional ::FieldOptions::CType, :ctype, 1
|
192
|
+
optional ::FieldOptions::CType, :ctype, 1, :default => ::FieldOptions::CType::STRING
|
193
|
+
optional :bool, :packed, 2
|
194
|
+
optional :bool, :lazy, 5, :default => false
|
195
|
+
optional :bool, :deprecated, 3, :default => false
|
185
196
|
optional :string, :experimental_map_key, 9
|
197
|
+
optional :bool, :weak, 10, :default => false
|
186
198
|
repeated ::UninterpretedOption, :uninterpreted_option, 999
|
187
199
|
|
188
200
|
gen_methods! # new fields ignored after this point
|
189
201
|
end
|
190
202
|
|
191
203
|
class EnumOptions < ::ProtocolBuffers::Message
|
204
|
+
optional :bool, :allow_alias, 2, :default => true
|
192
205
|
repeated ::UninterpretedOption, :uninterpreted_option, 999
|
193
206
|
|
194
207
|
gen_methods! # new fields ignored after this point
|
@@ -214,7 +227,7 @@ end
|
|
214
227
|
|
215
228
|
class UninterpretedOption < ::ProtocolBuffers::Message
|
216
229
|
# forward declarations
|
217
|
-
class
|
230
|
+
class NamePart < ::ProtocolBuffers::Message; end
|
218
231
|
|
219
232
|
# nested messages
|
220
233
|
class NamePart < ::ProtocolBuffers::Message
|
@@ -230,6 +243,26 @@ class UninterpretedOption < ::ProtocolBuffers::Message
|
|
230
243
|
optional :int64, :negative_int_value, 5
|
231
244
|
optional :double, :double_value, 6
|
232
245
|
optional :bytes, :string_value, 7
|
246
|
+
optional :string, :aggregate_value, 8
|
247
|
+
|
248
|
+
gen_methods! # new fields ignored after this point
|
249
|
+
end
|
250
|
+
|
251
|
+
class SourceCodeInfo < ::ProtocolBuffers::Message
|
252
|
+
# forward declarations
|
253
|
+
class Location < ::ProtocolBuffers::Message; end
|
254
|
+
|
255
|
+
# nested messages
|
256
|
+
class Location < ::ProtocolBuffers::Message
|
257
|
+
repeated :int32, :path, 1
|
258
|
+
repeated :int32, :span, 2
|
259
|
+
optional :string, :leading_comments, 3
|
260
|
+
optional :string, :trailing_comments, 4
|
261
|
+
|
262
|
+
gen_methods! # new fields ignored after this point
|
263
|
+
end
|
264
|
+
|
265
|
+
repeated ::SourceCodeInfo::Location, :location, 1
|
233
266
|
|
234
267
|
gen_methods! # new fields ignored after this point
|
235
268
|
end
|
@@ -55,18 +55,29 @@ message FileDescriptorSet {
|
|
55
55
|
// Describes a complete .proto file.
|
56
56
|
message FileDescriptorProto {
|
57
57
|
optional string name = 1; // file name, relative to root of source tree
|
58
|
-
optional string
|
58
|
+
optional string package = 2; // e.g. "foo", "foo.bar", etc.
|
59
59
|
|
60
60
|
// Names of files imported by this file.
|
61
61
|
repeated string dependency = 3;
|
62
|
+
// Indexes of the public imported files in the dependency list above.
|
63
|
+
repeated int32 public_dependency = 10;
|
64
|
+
// Indexes of the weak imported files in the dependency list.
|
65
|
+
// For Google-internal migration only. Do not use.
|
66
|
+
repeated int32 weak_dependency = 11;
|
62
67
|
|
63
68
|
// All top-level definitions in this file.
|
64
69
|
repeated DescriptorProto message_type = 4;
|
65
70
|
repeated EnumDescriptorProto enum_type = 5;
|
66
|
-
repeated ServiceDescriptorProto
|
71
|
+
repeated ServiceDescriptorProto service = 6;
|
67
72
|
repeated FieldDescriptorProto extension = 7;
|
68
73
|
|
69
74
|
optional FileOptions options = 8;
|
75
|
+
|
76
|
+
// This field contains optional information about the original source code.
|
77
|
+
// You may safely remove this entire field whithout harming runtime
|
78
|
+
// functionality of the descriptors -- the information is needed only by
|
79
|
+
// development tools.
|
80
|
+
optional SourceCodeInfo source_code_info = 9;
|
70
81
|
}
|
71
82
|
|
72
83
|
// Describes a message type.
|
@@ -95,13 +106,13 @@ message FieldDescriptorProto {
|
|
95
106
|
// Order is weird for historical reasons.
|
96
107
|
TYPE_DOUBLE = 1;
|
97
108
|
TYPE_FLOAT = 2;
|
98
|
-
|
99
|
-
|
100
|
-
|
109
|
+
// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
|
110
|
+
// negative values are likely.
|
111
|
+
TYPE_INT64 = 3;
|
101
112
|
TYPE_UINT64 = 4;
|
102
|
-
|
103
|
-
|
104
|
-
|
113
|
+
// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
|
114
|
+
// negative values are likely.
|
115
|
+
TYPE_INT32 = 5;
|
105
116
|
TYPE_FIXED64 = 6;
|
106
117
|
TYPE_FIXED32 = 7;
|
107
118
|
TYPE_BOOL = 8;
|
@@ -117,7 +128,7 @@ message FieldDescriptorProto {
|
|
117
128
|
TYPE_SFIXED64 = 16;
|
118
129
|
TYPE_SINT32 = 17; // Uses ZigZag encoding.
|
119
130
|
TYPE_SINT64 = 18; // Uses ZigZag encoding.
|
120
|
-
}
|
131
|
+
};
|
121
132
|
|
122
133
|
enum Label {
|
123
134
|
// 0 is reserved for errors
|
@@ -125,7 +136,7 @@ message FieldDescriptorProto {
|
|
125
136
|
LABEL_REQUIRED = 2;
|
126
137
|
LABEL_REPEATED = 3;
|
127
138
|
// TODO(sanjay): Should we add LABEL_MAP?
|
128
|
-
}
|
139
|
+
};
|
129
140
|
|
130
141
|
optional string name = 1;
|
131
142
|
optional int32 number = 3;
|
@@ -193,6 +204,7 @@ message MethodDescriptorProto {
|
|
193
204
|
optional MethodOptions options = 4;
|
194
205
|
}
|
195
206
|
|
207
|
+
|
196
208
|
// ===================================================================
|
197
209
|
// Options
|
198
210
|
|
@@ -214,10 +226,15 @@ message MethodDescriptorProto {
|
|
214
226
|
// through 99999. It is up to you to ensure that you do not use the
|
215
227
|
// same number for multiple options.
|
216
228
|
// * For options which will be published and used publicly by multiple
|
217
|
-
// independent entities, e-mail
|
218
|
-
//
|
219
|
-
//
|
220
|
-
//
|
229
|
+
// independent entities, e-mail protobuf-global-extension-registry@google.com
|
230
|
+
// 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
|
237
|
+
// If this turns out to be popular, a web service will be set up
|
221
238
|
// to automatically assign option numbers.
|
222
239
|
|
223
240
|
|
@@ -245,19 +262,46 @@ message FileOptions {
|
|
245
262
|
// top-level extensions defined in the file.
|
246
263
|
optional bool java_multiple_files = 10 [default=false];
|
247
264
|
|
265
|
+
// 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.
|
269
|
+
optional bool java_generate_equals_and_hash = 20 [default=false];
|
270
|
+
|
248
271
|
// Generated classes can be optimized for speed or code size.
|
249
272
|
enum OptimizeMode {
|
250
|
-
SPEED = 1;
|
251
|
-
|
273
|
+
SPEED = 1; // Generate complete code for parsing, serialization,
|
274
|
+
// etc.
|
275
|
+
CODE_SIZE = 2; // Use ReflectionOps to implement these methods.
|
276
|
+
LITE_RUNTIME = 3; // Generate code using MessageLite and the lite runtime.
|
252
277
|
}
|
253
|
-
optional OptimizeMode optimize_for = 9 [default=
|
278
|
+
optional OptimizeMode optimize_for = 9 [default=SPEED];
|
279
|
+
|
280
|
+
// Sets the Go package where structs generated from this .proto will be
|
281
|
+
// placed. There is no default.
|
282
|
+
optional string go_package = 11;
|
254
283
|
|
255
284
|
|
285
|
+
|
286
|
+
// Should generic services be generated in each language? "Generic" services
|
287
|
+
// are not specific to any particular RPC system. They are generated by the
|
288
|
+
// main code generators in each language (without additional plugins).
|
289
|
+
// Generic services were the only kind of service generation supported by
|
290
|
+
// early versions of proto2.
|
291
|
+
//
|
292
|
+
// Generic services are now considered deprecated in favor of using plugins
|
293
|
+
// that generate code specific to your particular RPC system. Therefore,
|
294
|
+
// these default to false. Old code which depends on generic services should
|
295
|
+
// explicitly set them to true.
|
296
|
+
optional bool cc_generic_services = 16 [default=false];
|
297
|
+
optional bool java_generic_services = 17 [default=false];
|
298
|
+
optional bool py_generic_services = 18 [default=false];
|
299
|
+
|
256
300
|
// The parser stores options it doesn't recognize here. See above.
|
257
301
|
repeated UninterpretedOption uninterpreted_option = 999;
|
258
302
|
|
259
303
|
// Clients can define custom options in extensions of this message. See above.
|
260
|
-
|
304
|
+
extensions 1000 to max;
|
261
305
|
}
|
262
306
|
|
263
307
|
message MessageOptions {
|
@@ -281,11 +325,16 @@ message MessageOptions {
|
|
281
325
|
// the protocol compiler.
|
282
326
|
optional bool message_set_wire_format = 1 [default=false];
|
283
327
|
|
328
|
+
// Disables the generation of the standard "descriptor()" accessor, which can
|
329
|
+
// conflict with a field of the same name. This is meant to make migration
|
330
|
+
// from proto1 easier; new code should avoid fields named "descriptor".
|
331
|
+
optional bool no_standard_descriptor_accessor = 2 [default=false];
|
332
|
+
|
284
333
|
// The parser stores options it doesn't recognize here. See above.
|
285
334
|
repeated UninterpretedOption uninterpreted_option = 999;
|
286
335
|
|
287
336
|
// Clients can define custom options in extensions of this message. See above.
|
288
|
-
|
337
|
+
extensions 1000 to max;
|
289
338
|
}
|
290
339
|
|
291
340
|
message FieldOptions {
|
@@ -293,12 +342,58 @@ message FieldOptions {
|
|
293
342
|
// representation of the field than it normally would. See the specific
|
294
343
|
// options below. This option is not yet implemented in the open source
|
295
344
|
// release -- sorry, we'll try to include it in a future version!
|
296
|
-
optional CType ctype = 1;
|
345
|
+
optional CType ctype = 1 [default = STRING];
|
297
346
|
enum CType {
|
347
|
+
// Default mode.
|
348
|
+
STRING = 0;
|
349
|
+
|
298
350
|
CORD = 1;
|
299
351
|
|
300
352
|
STRING_PIECE = 2;
|
301
353
|
}
|
354
|
+
// The packed option can be enabled for repeated primitive fields to enable
|
355
|
+
// a more efficient representation on the wire. Rather than repeatedly
|
356
|
+
// writing the tag and type for each element, the entire array is encoded as
|
357
|
+
// a single length-delimited blob.
|
358
|
+
optional bool packed = 2;
|
359
|
+
|
360
|
+
|
361
|
+
|
362
|
+
// Should this field be parsed lazily? Lazy applies only to message-type
|
363
|
+
// fields. It means that when the outer message is initially parsed, the
|
364
|
+
// inner message's contents will not be parsed but instead stored in encoded
|
365
|
+
// form. The inner message will actually be parsed when it is first accessed.
|
366
|
+
//
|
367
|
+
// This is only a hint. Implementations are free to choose whether to use
|
368
|
+
// eager or lazy parsing regardless of the value of this option. However,
|
369
|
+
// setting this option true suggests that the protocol author believes that
|
370
|
+
// using lazy parsing on this field is worth the additional bookkeeping
|
371
|
+
// overhead typically needed to implement it.
|
372
|
+
//
|
373
|
+
// This option does not affect the public interface of any generated code;
|
374
|
+
// all method signatures remain the same. Furthermore, thread-safety of the
|
375
|
+
// interface is not affected by this option; const methods remain safe to
|
376
|
+
// call from multiple threads concurrently, while non-const methods continue
|
377
|
+
// to require exclusive access.
|
378
|
+
//
|
379
|
+
//
|
380
|
+
// Note that implementations may choose not to check required fields within
|
381
|
+
// a lazy sub-message. That is, calling IsInitialized() on the outher message
|
382
|
+
// may return true even if the inner message has missing required fields.
|
383
|
+
// This is necessary because otherwise the inner message would have to be
|
384
|
+
// parsed in order to perform the check, defeating the purpose of lazy
|
385
|
+
// parsing. An implementation which chooses not to check required fields
|
386
|
+
// must be consistent about it. That is, for any particular sub-message, the
|
387
|
+
// implementation must either *always* check its required fields, or *never*
|
388
|
+
// check its required fields, regardless of whether or not the message has
|
389
|
+
// been parsed.
|
390
|
+
optional bool lazy = 5 [default=false];
|
391
|
+
|
392
|
+
// Is this field deprecated?
|
393
|
+
// Depending on the target platform, this can emit Deprecated annotations
|
394
|
+
// for accessors, or it will be completely ignored; in the very least, this
|
395
|
+
// is a formalization for deprecating fields.
|
396
|
+
optional bool deprecated = 3 [default=false];
|
302
397
|
|
303
398
|
// EXPERIMENTAL. DO NOT USE.
|
304
399
|
// For "map" fields, the name of the field in the enclosed type that
|
@@ -314,19 +409,27 @@ message FieldOptions {
|
|
314
409
|
// TODO: Fully-implement this, then remove the "experimental_" prefix.
|
315
410
|
optional string experimental_map_key = 9;
|
316
411
|
|
412
|
+
// For Google-internal migration only. Do not use.
|
413
|
+
optional bool weak = 10 [default=false];
|
414
|
+
|
317
415
|
// The parser stores options it doesn't recognize here. See above.
|
318
416
|
repeated UninterpretedOption uninterpreted_option = 999;
|
319
417
|
|
320
418
|
// Clients can define custom options in extensions of this message. See above.
|
321
|
-
|
419
|
+
extensions 1000 to max;
|
322
420
|
}
|
323
421
|
|
324
422
|
message EnumOptions {
|
423
|
+
|
424
|
+
// Set this option to false to disallow mapping different tag names to a same
|
425
|
+
// value.
|
426
|
+
optional bool allow_alias = 2 [default=true];
|
427
|
+
|
325
428
|
// The parser stores options it doesn't recognize here. See above.
|
326
429
|
repeated UninterpretedOption uninterpreted_option = 999;
|
327
430
|
|
328
431
|
// Clients can define custom options in extensions of this message. See above.
|
329
|
-
|
432
|
+
extensions 1000 to max;
|
330
433
|
}
|
331
434
|
|
332
435
|
message EnumValueOptions {
|
@@ -334,7 +437,7 @@ message EnumValueOptions {
|
|
334
437
|
repeated UninterpretedOption uninterpreted_option = 999;
|
335
438
|
|
336
439
|
// Clients can define custom options in extensions of this message. See above.
|
337
|
-
|
440
|
+
extensions 1000 to max;
|
338
441
|
}
|
339
442
|
|
340
443
|
message ServiceOptions {
|
@@ -348,7 +451,7 @@ message ServiceOptions {
|
|
348
451
|
repeated UninterpretedOption uninterpreted_option = 999;
|
349
452
|
|
350
453
|
// Clients can define custom options in extensions of this message. See above.
|
351
|
-
|
454
|
+
extensions 1000 to max;
|
352
455
|
}
|
353
456
|
|
354
457
|
message MethodOptions {
|
@@ -362,9 +465,10 @@ message MethodOptions {
|
|
362
465
|
repeated UninterpretedOption uninterpreted_option = 999;
|
363
466
|
|
364
467
|
// Clients can define custom options in extensions of this message. See above.
|
365
|
-
|
468
|
+
extensions 1000 to max;
|
366
469
|
}
|
367
470
|
|
471
|
+
|
368
472
|
// A message representing a option the parser does not recognize. This only
|
369
473
|
// appears in options protos created by the compiler::Parser class.
|
370
474
|
// DescriptorPool resolves these when building Descriptor objects. Therefore,
|
@@ -390,4 +494,127 @@ message UninterpretedOption {
|
|
390
494
|
optional int64 negative_int_value = 5;
|
391
495
|
optional double double_value = 6;
|
392
496
|
optional bytes string_value = 7;
|
497
|
+
optional string aggregate_value = 8;
|
498
|
+
}
|
499
|
+
|
500
|
+
// ===================================================================
|
501
|
+
// Optional source code info
|
502
|
+
|
503
|
+
// Encapsulates information about the original source file from which a
|
504
|
+
// FileDescriptorProto was generated.
|
505
|
+
message SourceCodeInfo {
|
506
|
+
// A Location identifies a piece of source code in a .proto file which
|
507
|
+
// corresponds to a particular definition. This information is intended
|
508
|
+
// to be useful to IDEs, code indexers, documentation generators, and similar
|
509
|
+
// tools.
|
510
|
+
//
|
511
|
+
// For example, say we have a file like:
|
512
|
+
// message Foo {
|
513
|
+
// optional string foo = 1;
|
514
|
+
// }
|
515
|
+
// Let's look at just the field definition:
|
516
|
+
// optional string foo = 1;
|
517
|
+
// ^ ^^ ^^ ^ ^^^
|
518
|
+
// a bc de f ghi
|
519
|
+
// We have the following locations:
|
520
|
+
// span path represents
|
521
|
+
// [a,i) [ 4, 0, 2, 0 ] The whole field definition.
|
522
|
+
// [a,b) [ 4, 0, 2, 0, 4 ] The label (optional).
|
523
|
+
// [c,d) [ 4, 0, 2, 0, 5 ] The type (string).
|
524
|
+
// [e,f) [ 4, 0, 2, 0, 1 ] The name (foo).
|
525
|
+
// [g,h) [ 4, 0, 2, 0, 3 ] The number (1).
|
526
|
+
//
|
527
|
+
// Notes:
|
528
|
+
// - A location may refer to a repeated field itself (i.e. not to any
|
529
|
+
// particular index within it). This is used whenever a set of elements are
|
530
|
+
// logically enclosed in a single code segment. For example, an entire
|
531
|
+
// extend block (possibly containing multiple extension definitions) will
|
532
|
+
// have an outer location whose path refers to the "extensions" repeated
|
533
|
+
// field without an index.
|
534
|
+
// - Multiple locations may have the same path. This happens when a single
|
535
|
+
// logical declaration is spread out across multiple places. The most
|
536
|
+
// obvious example is the "extend" block again -- there may be multiple
|
537
|
+
// extend blocks in the same scope, each of which will have the same path.
|
538
|
+
// - A location's span is not always a subset of its parent's span. For
|
539
|
+
// example, the "extendee" of an extension declaration appears at the
|
540
|
+
// beginning of the "extend" block and is shared by all extensions within
|
541
|
+
// the block.
|
542
|
+
// - Just because a location's span is a subset of some other location's span
|
543
|
+
// does not mean that it is a descendent. For example, a "group" defines
|
544
|
+
// both a type and a field in a single declaration. Thus, the locations
|
545
|
+
// corresponding to the type and field and their components will overlap.
|
546
|
+
// - Code which tries to interpret locations should probably be designed to
|
547
|
+
// ignore those that it doesn't understand, as more types of locations could
|
548
|
+
// be recorded in the future.
|
549
|
+
repeated Location location = 1;
|
550
|
+
message Location {
|
551
|
+
// Identifies which part of the FileDescriptorProto was defined at this
|
552
|
+
// location.
|
553
|
+
//
|
554
|
+
// Each element is a field number or an index. They form a path from
|
555
|
+
// the root FileDescriptorProto to the place where the definition. For
|
556
|
+
// example, this path:
|
557
|
+
// [ 4, 3, 2, 7, 1 ]
|
558
|
+
// refers to:
|
559
|
+
// file.message_type(3) // 4, 3
|
560
|
+
// .field(7) // 2, 7
|
561
|
+
// .name() // 1
|
562
|
+
// This is because FileDescriptorProto.message_type has field number 4:
|
563
|
+
// repeated DescriptorProto message_type = 4;
|
564
|
+
// and DescriptorProto.field has field number 2:
|
565
|
+
// repeated FieldDescriptorProto field = 2;
|
566
|
+
// and FieldDescriptorProto.name has field number 1:
|
567
|
+
// optional string name = 1;
|
568
|
+
//
|
569
|
+
// Thus, the above path gives the location of a field name. If we removed
|
570
|
+
// the last element:
|
571
|
+
// [ 4, 3, 2, 7 ]
|
572
|
+
// this path refers to the whole field declaration (from the beginning
|
573
|
+
// of the label to the terminating semicolon).
|
574
|
+
repeated int32 path = 1 [packed=true];
|
575
|
+
|
576
|
+
// Always has exactly three or four elements: start line, start column,
|
577
|
+
// end line (optional, otherwise assumed same as start line), end column.
|
578
|
+
// These are packed into a single field for efficiency. Note that line
|
579
|
+
// and column numbers are zero-based -- typically you will want to add
|
580
|
+
// 1 to each before displaying to a user.
|
581
|
+
repeated int32 span = 2 [packed=true];
|
582
|
+
|
583
|
+
// If this SourceCodeInfo represents a complete declaration, these are any
|
584
|
+
// comments appearing before and after the declaration which appear to be
|
585
|
+
// attached to the declaration.
|
586
|
+
//
|
587
|
+
// A series of line comments appearing on consecutive lines, with no other
|
588
|
+
// tokens appearing on those lines, will be treated as a single comment.
|
589
|
+
//
|
590
|
+
// Only the comment content is provided; comment markers (e.g. //) are
|
591
|
+
// stripped out. For block comments, leading whitespace and an asterisk
|
592
|
+
// will be stripped from the beginning of each line other than the first.
|
593
|
+
// Newlines are included in the output.
|
594
|
+
//
|
595
|
+
// Examples:
|
596
|
+
//
|
597
|
+
// optional int32 foo = 1; // Comment attached to foo.
|
598
|
+
// // Comment attached to bar.
|
599
|
+
// optional int32 bar = 2;
|
600
|
+
//
|
601
|
+
// optional string baz = 3;
|
602
|
+
// // Comment attached to baz.
|
603
|
+
// // Another line attached to baz.
|
604
|
+
//
|
605
|
+
// // Comment attached to qux.
|
606
|
+
// //
|
607
|
+
// // Another line attached to qux.
|
608
|
+
// optional double qux = 4;
|
609
|
+
//
|
610
|
+
// optional string corge = 5;
|
611
|
+
// /* Block comment attached
|
612
|
+
// * to corge. Leading asterisks
|
613
|
+
// * will be removed. */
|
614
|
+
// /* Block comment attached to
|
615
|
+
// * grault. */
|
616
|
+
// optional int32 grault = 6;
|
617
|
+
optional string leading_comments = 3;
|
618
|
+
optional string trailing_comments = 4;
|
619
|
+
}
|
393
620
|
}
|