ruby-protocol-buffers 0.8.4

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 (41) hide show
  1. data/.document +3 -0
  2. data/.gitignore +11 -0
  3. data/LICENSE +22 -0
  4. data/README +82 -0
  5. data/Rakefile +56 -0
  6. data/VERSION +1 -0
  7. data/bin/ruby-protoc +55 -0
  8. data/debian/changelog +105 -0
  9. data/debian/compatability +1 -0
  10. data/debian/control +12 -0
  11. data/debian/libprotobuf-ruby1.8.install +7 -0
  12. data/debian/protocol_buffers.rb +3 -0
  13. data/debian/rules +13 -0
  14. data/examples/json_protobuf.rb +90 -0
  15. data/ext/extconf.disabled.rb +3 -0
  16. data/ext/varint.c +65 -0
  17. data/lib/protocol_buffers.rb +5 -0
  18. data/lib/protocol_buffers/compiler.rb +48 -0
  19. data/lib/protocol_buffers/compiler/descriptor.pb.rb +236 -0
  20. data/lib/protocol_buffers/compiler/descriptor.proto +393 -0
  21. data/lib/protocol_buffers/compiler/file_descriptor_to_d.rb +195 -0
  22. data/lib/protocol_buffers/compiler/file_descriptor_to_ruby.rb +173 -0
  23. data/lib/protocol_buffers/limited_io.rb +33 -0
  24. data/lib/protocol_buffers/runtime/decoder.rb +65 -0
  25. data/lib/protocol_buffers/runtime/encoder.rb +53 -0
  26. data/lib/protocol_buffers/runtime/enum.rb +4 -0
  27. data/lib/protocol_buffers/runtime/extend.rb +1 -0
  28. data/lib/protocol_buffers/runtime/field.rb +550 -0
  29. data/lib/protocol_buffers/runtime/message.rb +494 -0
  30. data/lib/protocol_buffers/runtime/service.rb +1 -0
  31. data/lib/protocol_buffers/runtime/varint.rb +62 -0
  32. data/spec/compiler_spec.rb +19 -0
  33. data/spec/fields_spec.rb +49 -0
  34. data/spec/proto_files/depends.proto +5 -0
  35. data/spec/proto_files/featureful.proto +54 -0
  36. data/spec/proto_files/no_package.proto +10 -0
  37. data/spec/proto_files/simple.proto +5 -0
  38. data/spec/runtime_spec.rb +430 -0
  39. data/spec/spec.opts +1 -0
  40. data/spec/spec_helper.rb +8 -0
  41. metadata +128 -0
@@ -0,0 +1,3 @@
1
+ require 'mkmf'
2
+
3
+ create_makefile "ruby_protobufs"
data/ext/varint.c ADDED
@@ -0,0 +1,65 @@
1
+ #include "ruby.h"
2
+
3
+ static VALUE Protobuf, Varint;
4
+ static ID getbyte, putbyte;
5
+
6
+ static VALUE varint_encode(VALUE module, VALUE io, VALUE int_valV)
7
+ {
8
+ /* unsigned for the bit shifting ops */
9
+ unsigned long long int_val = (unsigned long long)NUM2LL(int_valV);
10
+ unsigned char byte;
11
+ while (1) {
12
+ byte = int_val & 0x7f;
13
+ int_val >>= 7;
14
+ if (int_val == 0) {
15
+ rb_funcall(io, putbyte, 1, INT2FIX(byte));
16
+ return Qnil;
17
+ } else {
18
+ rb_funcall(io, putbyte, 1, INT2FIX(byte | 0x80));
19
+ }
20
+ }
21
+ }
22
+
23
+ static VALUE varint_decode(VALUE module, VALUE io)
24
+ {
25
+ unsigned long long int_val = 0;
26
+ unsigned shift = 0;
27
+ unsigned char byte;
28
+
29
+ while (1) {
30
+ if (shift >= 64) {
31
+ rb_raise(rb_eArgError, "too many bytes when decoding varint");
32
+ }
33
+ byte = (unsigned char)FIX2INT(rb_funcall(io, getbyte, 0));
34
+ int_val |= ((unsigned long long)(byte & 0x7f)) << shift;
35
+ shift += 7;
36
+ if ((byte & 0x80) == 0) {
37
+ /* return ULL2NUM(int_val); */
38
+ return LL2NUM((long long)int_val);
39
+ }
40
+ }
41
+ }
42
+
43
+ void Init_ruby_protobufs()
44
+ {
45
+ Protobuf = rb_define_module("Protobuf");
46
+ Varint = rb_define_module_under(Protobuf, "Varint");
47
+
48
+ VALUE zero = INT2FIX(0);
49
+ VALUE test_io = rb_class_new_instance(1, &zero,
50
+ rb_const_get(rb_cObject, rb_intern("IO")));
51
+
52
+ /* hackish way to support both 1.8.6 and 1.8.7+ */
53
+ getbyte = rb_intern("getbyte");
54
+ if (!rb_respond_to(test_io, getbyte)) {
55
+ getbyte = rb_intern("getc");
56
+ }
57
+
58
+ /* TODO: check the api docs -- what happens to test_io here?
59
+ * does it just leak? */
60
+
61
+ putbyte = rb_intern("putc");
62
+
63
+ rb_define_module_function(Varint, "encode", varint_encode, 2);
64
+ rb_define_module_function(Varint, "decode", varint_decode, 1);
65
+ }
@@ -0,0 +1,5 @@
1
+ module ProtocolBuffers
2
+ VERSION = File.read(File.join(File.dirname(__FILE__), "..", "VERSION")).chomp
3
+ end
4
+
5
+ require 'protocol_buffers/runtime/message'
@@ -0,0 +1,48 @@
1
+ require 'protocol_buffers/compiler/descriptor.pb'
2
+
3
+ module ProtocolBuffers
4
+ class CompileError < StandardError; end
5
+
6
+ module Compiler
7
+ def self.compile(output_filename, input_files, opts = {})
8
+ input_files = Array(input_files) unless input_files.is_a?(Array)
9
+ raise(ArgumentError, "Need at least one input file") if input_files.empty?
10
+ other_opts = ""
11
+ (opts[:include_dirs] || []).each { |d| other_opts += " -I#{d}" }
12
+ input_files.each { |f| other_opts += " -I#{File.dirname(f)}" }
13
+
14
+ cmd = "protoc #{other_opts} -o#{output_filename} #{input_files.join(' ')}"
15
+ rc = system(cmd)
16
+ raise(CompileError, $?.exitstatus.to_s) unless rc
17
+ true
18
+ end
19
+
20
+ def self.compile_and_load(input_files, opts = {})
21
+ require 'tempfile'
22
+ require 'protocol_buffers/compiler/file_descriptor_to_ruby'
23
+
24
+ tempfile = Tempfile.new("protocol_buffers_spec")
25
+ compile(tempfile.path, input_files, opts)
26
+ descriptor_set = FileDescriptorSet.parse(tempfile)
27
+ tempfile.close(true)
28
+ descriptor_set.file.each do |file|
29
+ parsed = FileDescriptorToRuby.new(file)
30
+ output = Tempfile.new("protocol_buffers_spec_parsed")
31
+ parsed.write(output)
32
+ output.flush
33
+ load output.path
34
+ output.close(true)
35
+ end
36
+ true
37
+ end
38
+
39
+ def self.compile_and_load_string(input, opts = {})
40
+ require 'tempfile'
41
+ tempfile = Tempfile.new("protocol_buffers_load_string")
42
+ tempfile.write(input)
43
+ tempfile.flush
44
+ (opts[:include_dirs] ||= []) << File.dirname(tempfile.path)
45
+ compile_and_load(tempfile.path, opts)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,236 @@
1
+ #!/usr/bin/env ruby
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+
4
+ require 'protocol_buffers/runtime/message'
5
+
6
+ # forward declarations
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
+
24
+ class FileDescriptorSet < ::ProtocolBuffers::Message
25
+ repeated ::FileDescriptorProto, :file, 1
26
+
27
+ gen_methods! # new fields ignored after this point
28
+ end
29
+
30
+ class FileDescriptorProto < ::ProtocolBuffers::Message
31
+ optional :string, :name, 1
32
+ optional :string, :package_, 2
33
+ repeated :string, :dependency, 3
34
+ repeated ::DescriptorProto, :message_type, 4
35
+ repeated ::EnumDescriptorProto, :enum_type, 5
36
+ repeated ::ServiceDescriptorProto, :service_, 6
37
+ repeated ::FieldDescriptorProto, :extension, 7
38
+ optional ::FileOptions, :options, 8
39
+
40
+ gen_methods! # new fields ignored after this point
41
+ end
42
+
43
+ class DescriptorProto < ::ProtocolBuffers::Message
44
+ # forward declarations
45
+ class ::ExtensionRange < ::ProtocolBuffers::Message; end
46
+
47
+ # nested messages
48
+ class ExtensionRange < ::ProtocolBuffers::Message
49
+ optional :int32, :start, 1
50
+ optional :int32, :end, 2
51
+
52
+ gen_methods! # new fields ignored after this point
53
+ end
54
+
55
+ optional :string, :name, 1
56
+ repeated ::FieldDescriptorProto, :field, 2
57
+ repeated ::FieldDescriptorProto, :extension, 6
58
+ repeated ::DescriptorProto, :nested_type, 3
59
+ repeated ::EnumDescriptorProto, :enum_type, 4
60
+ repeated ::DescriptorProto::ExtensionRange, :extension_range, 5
61
+ optional ::MessageOptions, :options, 7
62
+
63
+ gen_methods! # new fields ignored after this point
64
+ end
65
+
66
+ class FieldDescriptorProto < ::ProtocolBuffers::Message
67
+ # forward declarations
68
+ module ::Type; end
69
+ module ::Label; end
70
+
71
+ # nested enums
72
+ module Type
73
+ include ::ProtocolBuffers::Enum
74
+ TYPE_DOUBLE = 1
75
+ TYPE_FLOAT = 2
76
+ TYPE_INT64 = 3
77
+ TYPE_UINT64 = 4
78
+ TYPE_INT32 = 5
79
+ TYPE_FIXED64 = 6
80
+ TYPE_FIXED32 = 7
81
+ TYPE_BOOL = 8
82
+ TYPE_STRING = 9
83
+ TYPE_GROUP = 10
84
+ TYPE_MESSAGE = 11
85
+ TYPE_BYTES = 12
86
+ TYPE_UINT32 = 13
87
+ TYPE_ENUM = 14
88
+ TYPE_SFIXED32 = 15
89
+ TYPE_SFIXED64 = 16
90
+ TYPE_SINT32 = 17
91
+ TYPE_SINT64 = 18
92
+ end
93
+
94
+ module Label
95
+ include ::ProtocolBuffers::Enum
96
+ LABEL_OPTIONAL = 1
97
+ LABEL_REQUIRED = 2
98
+ LABEL_REPEATED = 3
99
+ end
100
+
101
+ optional :string, :name, 1
102
+ optional :int32, :number, 3
103
+ optional ::FieldDescriptorProto::Label, :label, 4
104
+ optional ::FieldDescriptorProto::Type, :type, 5
105
+ optional :string, :type_name, 6
106
+ optional :string, :extendee, 2
107
+ optional :string, :default_value, 7
108
+ optional ::FieldOptions, :options, 8
109
+
110
+ gen_methods! # new fields ignored after this point
111
+ end
112
+
113
+ class EnumDescriptorProto < ::ProtocolBuffers::Message
114
+ optional :string, :name, 1
115
+ repeated ::EnumValueDescriptorProto, :value, 2
116
+ optional ::EnumOptions, :options, 3
117
+
118
+ gen_methods! # new fields ignored after this point
119
+ end
120
+
121
+ class EnumValueDescriptorProto < ::ProtocolBuffers::Message
122
+ optional :string, :name, 1
123
+ optional :int32, :number, 2
124
+ optional ::EnumValueOptions, :options, 3
125
+
126
+ gen_methods! # new fields ignored after this point
127
+ end
128
+
129
+ class ServiceDescriptorProto < ::ProtocolBuffers::Message
130
+ optional :string, :name, 1
131
+ repeated ::MethodDescriptorProto, :method, 2
132
+ optional ::ServiceOptions, :options, 3
133
+
134
+ gen_methods! # new fields ignored after this point
135
+ end
136
+
137
+ class MethodDescriptorProto < ::ProtocolBuffers::Message
138
+ optional :string, :name, 1
139
+ optional :string, :input_type, 2
140
+ optional :string, :output_type, 3
141
+ optional ::MethodOptions, :options, 4
142
+
143
+ gen_methods! # new fields ignored after this point
144
+ end
145
+
146
+ class FileOptions < ::ProtocolBuffers::Message
147
+ # forward declarations
148
+ module ::OptimizeMode; end
149
+
150
+ # nested enums
151
+ module OptimizeMode
152
+ include ::ProtocolBuffers::Enum
153
+ SPEED = 1
154
+ CODE_SIZE = 2
155
+ end
156
+
157
+ optional :string, :java_package, 1
158
+ optional :string, :java_outer_classname, 8
159
+ optional :bool, :java_multiple_files, 10, :default => false
160
+ optional ::FileOptions::OptimizeMode, :optimize_for, 9, :default => ::FileOptions::OptimizeMode::CODE_SIZE
161
+ repeated ::UninterpretedOption, :uninterpreted_option, 999
162
+
163
+ gen_methods! # new fields ignored after this point
164
+ end
165
+
166
+ class MessageOptions < ::ProtocolBuffers::Message
167
+ optional :bool, :message_set_wire_format, 1, :default => false
168
+ repeated ::UninterpretedOption, :uninterpreted_option, 999
169
+
170
+ gen_methods! # new fields ignored after this point
171
+ end
172
+
173
+ class FieldOptions < ::ProtocolBuffers::Message
174
+ # forward declarations
175
+ module ::CType; end
176
+
177
+ # nested enums
178
+ module CType
179
+ include ::ProtocolBuffers::Enum
180
+ CORD = 1
181
+ STRING_PIECE = 2
182
+ end
183
+
184
+ optional ::FieldOptions::CType, :ctype, 1
185
+ optional :string, :experimental_map_key, 9
186
+ repeated ::UninterpretedOption, :uninterpreted_option, 999
187
+
188
+ gen_methods! # new fields ignored after this point
189
+ end
190
+
191
+ class EnumOptions < ::ProtocolBuffers::Message
192
+ repeated ::UninterpretedOption, :uninterpreted_option, 999
193
+
194
+ gen_methods! # new fields ignored after this point
195
+ end
196
+
197
+ class EnumValueOptions < ::ProtocolBuffers::Message
198
+ repeated ::UninterpretedOption, :uninterpreted_option, 999
199
+
200
+ gen_methods! # new fields ignored after this point
201
+ end
202
+
203
+ class ServiceOptions < ::ProtocolBuffers::Message
204
+ repeated ::UninterpretedOption, :uninterpreted_option, 999
205
+
206
+ gen_methods! # new fields ignored after this point
207
+ end
208
+
209
+ class MethodOptions < ::ProtocolBuffers::Message
210
+ repeated ::UninterpretedOption, :uninterpreted_option, 999
211
+
212
+ gen_methods! # new fields ignored after this point
213
+ end
214
+
215
+ class UninterpretedOption < ::ProtocolBuffers::Message
216
+ # forward declarations
217
+ class ::NamePart < ::ProtocolBuffers::Message; end
218
+
219
+ # nested messages
220
+ class NamePart < ::ProtocolBuffers::Message
221
+ required :string, :name_part, 1
222
+ required :bool, :is_extension, 2
223
+
224
+ gen_methods! # new fields ignored after this point
225
+ end
226
+
227
+ repeated ::UninterpretedOption::NamePart, :name, 2
228
+ optional :string, :identifier_value, 3
229
+ optional :uint64, :positive_int_value, 4
230
+ optional :int64, :negative_int_value, 5
231
+ optional :double, :double_value, 6
232
+ optional :bytes, :string_value, 7
233
+
234
+ gen_methods! # new fields ignored after this point
235
+ end
236
+
@@ -0,0 +1,393 @@
1
+ // Protocol Buffers - Google's data interchange format
2
+ // Copyright 2008 Google Inc. All rights reserved.
3
+ // http://code.google.com/p/protobuf/
4
+ //
5
+ // Redistribution and use in source and binary forms, with or without
6
+ // modification, are permitted provided that the following conditions are
7
+ // met:
8
+ //
9
+ // * Redistributions of source code must retain the above copyright
10
+ // notice, this list of conditions and the following disclaimer.
11
+ // * Redistributions in binary form must reproduce the above
12
+ // copyright notice, this list of conditions and the following disclaimer
13
+ // in the documentation and/or other materials provided with the
14
+ // distribution.
15
+ // * Neither the name of Google Inc. nor the names of its
16
+ // contributors may be used to endorse or promote products derived from
17
+ // this software without specific prior written permission.
18
+ //
19
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ // Author: kenton@google.com (Kenton Varda)
32
+ // Based on original Protocol Buffers design by
33
+ // Sanjay Ghemawat, Jeff Dean, and others.
34
+ //
35
+ // The messages in this file describe the definitions found in .proto files.
36
+ // A valid .proto file can be translated directly to a FileDescriptorProto
37
+ // without any other information (e.g. without reading its imports).
38
+
39
+
40
+
41
+ // package google.protobuf;
42
+ // option java_package = "com.google.protobuf";
43
+ // option java_outer_classname = "DescriptorProtos";
44
+
45
+ // descriptor.proto must be optimized for speed because reflection-based
46
+ // algorithms don't work during bootstrapping.
47
+ // option optimize_for = SPEED;
48
+
49
+ // The protocol compiler can output a FileDescriptorSet containing the .proto
50
+ // files it parses.
51
+ message FileDescriptorSet {
52
+ repeated FileDescriptorProto file = 1;
53
+ }
54
+
55
+ // Describes a complete .proto file.
56
+ message FileDescriptorProto {
57
+ optional string name = 1; // file name, relative to root of source tree
58
+ optional string package_ = 2; // e.g. "foo", "foo.bar", etc.
59
+
60
+ // Names of files imported by this file.
61
+ repeated string dependency = 3;
62
+
63
+ // All top-level definitions in this file.
64
+ repeated DescriptorProto message_type = 4;
65
+ repeated EnumDescriptorProto enum_type = 5;
66
+ repeated ServiceDescriptorProto service_ = 6;
67
+ repeated FieldDescriptorProto extension = 7;
68
+
69
+ optional FileOptions options = 8;
70
+ }
71
+
72
+ // Describes a message type.
73
+ message DescriptorProto {
74
+ optional string name = 1;
75
+
76
+ repeated FieldDescriptorProto field = 2;
77
+ repeated FieldDescriptorProto extension = 6;
78
+
79
+ repeated DescriptorProto nested_type = 3;
80
+ repeated EnumDescriptorProto enum_type = 4;
81
+
82
+ message ExtensionRange {
83
+ optional int32 start = 1;
84
+ optional int32 end = 2;
85
+ }
86
+ repeated ExtensionRange extension_range = 5;
87
+
88
+ optional MessageOptions options = 7;
89
+ }
90
+
91
+ // Describes a field within a message.
92
+ message FieldDescriptorProto {
93
+ enum Type {
94
+ // 0 is reserved for errors.
95
+ // Order is weird for historical reasons.
96
+ TYPE_DOUBLE = 1;
97
+ TYPE_FLOAT = 2;
98
+ TYPE_INT64 = 3; // Not ZigZag encoded. Negative numbers
99
+ // take 10 bytes. Use TYPE_SINT64 if negative
100
+ // values are likely.
101
+ TYPE_UINT64 = 4;
102
+ TYPE_INT32 = 5; // Not ZigZag encoded. Negative numbers
103
+ // take 10 bytes. Use TYPE_SINT32 if negative
104
+ // values are likely.
105
+ TYPE_FIXED64 = 6;
106
+ TYPE_FIXED32 = 7;
107
+ TYPE_BOOL = 8;
108
+ TYPE_STRING = 9;
109
+ TYPE_GROUP = 10; // Tag-delimited aggregate.
110
+ TYPE_MESSAGE = 11; // Length-delimited aggregate.
111
+
112
+ // New in version 2.
113
+ TYPE_BYTES = 12;
114
+ TYPE_UINT32 = 13;
115
+ TYPE_ENUM = 14;
116
+ TYPE_SFIXED32 = 15;
117
+ TYPE_SFIXED64 = 16;
118
+ TYPE_SINT32 = 17; // Uses ZigZag encoding.
119
+ TYPE_SINT64 = 18; // Uses ZigZag encoding.
120
+ }
121
+
122
+ enum Label {
123
+ // 0 is reserved for errors
124
+ LABEL_OPTIONAL = 1;
125
+ LABEL_REQUIRED = 2;
126
+ LABEL_REPEATED = 3;
127
+ // TODO(sanjay): Should we add LABEL_MAP?
128
+ }
129
+
130
+ optional string name = 1;
131
+ optional int32 number = 3;
132
+ optional Label label = 4;
133
+
134
+ // If type_name is set, this need not be set. If both this and type_name
135
+ // are set, this must be either TYPE_ENUM or TYPE_MESSAGE.
136
+ optional Type type = 5;
137
+
138
+ // For message and enum types, this is the name of the type. If the name
139
+ // starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
140
+ // rules are used to find the type (i.e. first the nested types within this
141
+ // message are searched, then within the parent, on up to the root
142
+ // namespace).
143
+ optional string type_name = 6;
144
+
145
+ // For extensions, this is the name of the type being extended. It is
146
+ // resolved in the same manner as type_name.
147
+ optional string extendee = 2;
148
+
149
+ // For numeric types, contains the original text representation of the value.
150
+ // For booleans, "true" or "false".
151
+ // For strings, contains the default text contents (not escaped in any way).
152
+ // For bytes, contains the C escaped value. All bytes >= 128 are escaped.
153
+ // TODO(kenton): Base-64 encode?
154
+ optional string default_value = 7;
155
+
156
+ optional FieldOptions options = 8;
157
+ }
158
+
159
+ // Describes an enum type.
160
+ message EnumDescriptorProto {
161
+ optional string name = 1;
162
+
163
+ repeated EnumValueDescriptorProto value = 2;
164
+
165
+ optional EnumOptions options = 3;
166
+ }
167
+
168
+ // Describes a value within an enum.
169
+ message EnumValueDescriptorProto {
170
+ optional string name = 1;
171
+ optional int32 number = 2;
172
+
173
+ optional EnumValueOptions options = 3;
174
+ }
175
+
176
+ // Describes a service.
177
+ message ServiceDescriptorProto {
178
+ optional string name = 1;
179
+ repeated MethodDescriptorProto method = 2;
180
+
181
+ optional ServiceOptions options = 3;
182
+ }
183
+
184
+ // Describes a method of a service.
185
+ message MethodDescriptorProto {
186
+ optional string name = 1;
187
+
188
+ // Input and output type names. These are resolved in the same way as
189
+ // FieldDescriptorProto.type_name, but must refer to a message type.
190
+ optional string input_type = 2;
191
+ optional string output_type = 3;
192
+
193
+ optional MethodOptions options = 4;
194
+ }
195
+
196
+ // ===================================================================
197
+ // Options
198
+
199
+ // Each of the definitions above may have "options" attached. These are
200
+ // just annotations which may cause code to be generated slightly differently
201
+ // or may contain hints for code that manipulates protocol messages.
202
+ //
203
+ // Clients may define custom options as extensions of the *Options messages.
204
+ // These extensions may not yet be known at parsing time, so the parser cannot
205
+ // store the values in them. Instead it stores them in a field in the *Options
206
+ // message called uninterpreted_option. This field must have the same name
207
+ // across all *Options messages. We then use this field to populate the
208
+ // extensions when we build a descriptor, at which point all protos have been
209
+ // parsed and so all extensions are known.
210
+ //
211
+ // Extension numbers for custom options may be chosen as follows:
212
+ // * For options which will only be used within a single application or
213
+ // organization, or for experimental options, use field numbers 50000
214
+ // through 99999. It is up to you to ensure that you do not use the
215
+ // same number for multiple options.
216
+ // * For options which will be published and used publicly by multiple
217
+ // independent entities, e-mail kenton@google.com to reserve extension
218
+ // numbers. Simply tell me how many you need and I'll send you back a
219
+ // set of numbers to use -- there's no need to explain how you intend to
220
+ // use them. If this turns out to be popular, a web service will be set up
221
+ // to automatically assign option numbers.
222
+
223
+
224
+ message FileOptions {
225
+
226
+ // Sets the Java package where classes generated from this .proto will be
227
+ // placed. By default, the proto package is used, but this is often
228
+ // inappropriate because proto packages do not normally start with backwards
229
+ // domain names.
230
+ optional string java_package = 1;
231
+
232
+
233
+ // If set, all the classes from the .proto file are wrapped in a single
234
+ // outer class with the given name. This applies to both Proto1
235
+ // (equivalent to the old "--one_java_file" option) and Proto2 (where
236
+ // a .proto always translates to a single class, but you may want to
237
+ // explicitly choose the class name).
238
+ optional string java_outer_classname = 8;
239
+
240
+ // If set true, then the Java code generator will generate a separate .java
241
+ // file for each top-level message, enum, and service defined in the .proto
242
+ // file. Thus, these types will *not* be nested inside the outer class
243
+ // named by java_outer_classname. However, the outer class will still be
244
+ // generated to contain the file's getDescriptor() method as well as any
245
+ // top-level extensions defined in the file.
246
+ optional bool java_multiple_files = 10 [default=false];
247
+
248
+ // Generated classes can be optimized for speed or code size.
249
+ enum OptimizeMode {
250
+ SPEED = 1; // Generate complete code for parsing, serialization, etc.
251
+ CODE_SIZE = 2; // Use ReflectionOps to implement these methods.
252
+ }
253
+ optional OptimizeMode optimize_for = 9 [default=CODE_SIZE];
254
+
255
+
256
+ // The parser stores options it doesn't recognize here. See above.
257
+ repeated UninterpretedOption uninterpreted_option = 999;
258
+
259
+ // Clients can define custom options in extensions of this message. See above.
260
+ // extensions 1000 to max;
261
+ }
262
+
263
+ message MessageOptions {
264
+ // Set true to use the old proto1 MessageSet wire format for extensions.
265
+ // This is provided for backwards-compatibility with the MessageSet wire
266
+ // format. You should not use this for any other reason: It's less
267
+ // efficient, has fewer features, and is more complicated.
268
+ //
269
+ // The message must be defined exactly as follows:
270
+ // message Foo {
271
+ // option message_set_wire_format = true;
272
+ // extensions 4 to max;
273
+ // }
274
+ // Note that the message cannot have any defined fields; MessageSets only
275
+ // have extensions.
276
+ //
277
+ // All extensions of your type must be singular messages; e.g. they cannot
278
+ // be int32s, enums, or repeated messages.
279
+ //
280
+ // Because this is an option, the above two restrictions are not enforced by
281
+ // the protocol compiler.
282
+ optional bool message_set_wire_format = 1 [default=false];
283
+
284
+ // The parser stores options it doesn't recognize here. See above.
285
+ repeated UninterpretedOption uninterpreted_option = 999;
286
+
287
+ // Clients can define custom options in extensions of this message. See above.
288
+ // extensions 1000 to max;
289
+ }
290
+
291
+ message FieldOptions {
292
+ // The ctype option instructs the C++ code generator to use a different
293
+ // representation of the field than it normally would. See the specific
294
+ // options below. This option is not yet implemented in the open source
295
+ // release -- sorry, we'll try to include it in a future version!
296
+ optional CType ctype = 1;
297
+ enum CType {
298
+ CORD = 1;
299
+
300
+ STRING_PIECE = 2;
301
+ }
302
+
303
+ // EXPERIMENTAL. DO NOT USE.
304
+ // For "map" fields, the name of the field in the enclosed type that
305
+ // is the key for this map. For example, suppose we have:
306
+ // message Item {
307
+ // required string name = 1;
308
+ // required string value = 2;
309
+ // }
310
+ // message Config {
311
+ // repeated Item items = 1 [experimental_map_key="name"];
312
+ // }
313
+ // In this situation, the map key for Item will be set to "name".
314
+ // TODO: Fully-implement this, then remove the "experimental_" prefix.
315
+ optional string experimental_map_key = 9;
316
+
317
+ // The parser stores options it doesn't recognize here. See above.
318
+ repeated UninterpretedOption uninterpreted_option = 999;
319
+
320
+ // Clients can define custom options in extensions of this message. See above.
321
+ // extensions 1000 to max;
322
+ }
323
+
324
+ message EnumOptions {
325
+ // The parser stores options it doesn't recognize here. See above.
326
+ repeated UninterpretedOption uninterpreted_option = 999;
327
+
328
+ // Clients can define custom options in extensions of this message. See above.
329
+ // extensions 1000 to max;
330
+ }
331
+
332
+ message EnumValueOptions {
333
+ // The parser stores options it doesn't recognize here. See above.
334
+ repeated UninterpretedOption uninterpreted_option = 999;
335
+
336
+ // Clients can define custom options in extensions of this message. See above.
337
+ // extensions 1000 to max;
338
+ }
339
+
340
+ message ServiceOptions {
341
+
342
+ // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
343
+ // framework. We apologize for hoarding these numbers to ourselves, but
344
+ // we were already using them long before we decided to release Protocol
345
+ // Buffers.
346
+
347
+ // The parser stores options it doesn't recognize here. See above.
348
+ repeated UninterpretedOption uninterpreted_option = 999;
349
+
350
+ // Clients can define custom options in extensions of this message. See above.
351
+ // extensions 1000 to max;
352
+ }
353
+
354
+ message MethodOptions {
355
+
356
+ // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
357
+ // framework. We apologize for hoarding these numbers to ourselves, but
358
+ // we were already using them long before we decided to release Protocol
359
+ // Buffers.
360
+
361
+ // The parser stores options it doesn't recognize here. See above.
362
+ repeated UninterpretedOption uninterpreted_option = 999;
363
+
364
+ // Clients can define custom options in extensions of this message. See above.
365
+ // extensions 1000 to max;
366
+ }
367
+
368
+ // A message representing a option the parser does not recognize. This only
369
+ // appears in options protos created by the compiler::Parser class.
370
+ // DescriptorPool resolves these when building Descriptor objects. Therefore,
371
+ // options protos in descriptor objects (e.g. returned by Descriptor::options(),
372
+ // or produced by Descriptor::CopyTo()) will never have UninterpretedOptions
373
+ // in them.
374
+ message UninterpretedOption {
375
+ // The name of the uninterpreted option. Each string represents a segment in
376
+ // a dot-separated name. is_extension is true iff a segment represents an
377
+ // extension (denoted with parentheses in options specs in .proto files).
378
+ // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
379
+ // "foo.(bar.baz).qux".
380
+ message NamePart {
381
+ required string name_part = 1;
382
+ required bool is_extension = 2;
383
+ }
384
+ repeated NamePart name = 2;
385
+
386
+ // The value of the uninterpreted option, in whatever type the tokenizer
387
+ // identified it as during parsing. Exactly one of these should be set.
388
+ optional string identifier_value = 3;
389
+ optional uint64 positive_int_value = 4;
390
+ optional int64 negative_int_value = 5;
391
+ optional double double_value = 6;
392
+ optional bytes string_value = 7;
393
+ }