1 // Go support for Protocol Buffers - Google's data interchange format
3 // Copyright 2010 The Go Authors. All rights reserved.
4 // https://github.com/golang/protobuf
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following disclaimer
14 // in the documentation and/or other materials provided with the
16 // * Neither the name of Google Inc. nor the names of its
17 // contributors may be used to endorse or promote products derived from
18 // this software without specific prior written permission.
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 // A feature-rich test file for the protocol compiler and libraries.
38 option go_package = "github.com/gogo/protobuf/proto/test_proto";
40 enum FOO { FOO1 = 1; };
47 required string Label = 1;
48 required string Type = 2;
52 // An enum, for completeness.
74 FUNCTION = 12; // last tag
77 // Some typical parameters
78 required KIND Kind = 1;
79 optional string Table = 2;
80 optional int32 Param = 3;
82 // Required, repeated and optional foreign fields.
83 required GoTestField RequiredField = 4;
84 repeated GoTestField RepeatedField = 5;
85 optional GoTestField OptionalField = 6;
87 // Required fields of all basic types
88 required bool F_Bool_required = 10;
89 required int32 F_Int32_required = 11;
90 required int64 F_Int64_required = 12;
91 required fixed32 F_Fixed32_required = 13;
92 required fixed64 F_Fixed64_required = 14;
93 required uint32 F_Uint32_required = 15;
94 required uint64 F_Uint64_required = 16;
95 required float F_Float_required = 17;
96 required double F_Double_required = 18;
97 required string F_String_required = 19;
98 required bytes F_Bytes_required = 101;
99 required sint32 F_Sint32_required = 102;
100 required sint64 F_Sint64_required = 103;
101 required sfixed32 F_Sfixed32_required = 104;
102 required sfixed64 F_Sfixed64_required = 105;
104 // Repeated fields of all basic types
105 repeated bool F_Bool_repeated = 20;
106 repeated int32 F_Int32_repeated = 21;
107 repeated int64 F_Int64_repeated = 22;
108 repeated fixed32 F_Fixed32_repeated = 23;
109 repeated fixed64 F_Fixed64_repeated = 24;
110 repeated uint32 F_Uint32_repeated = 25;
111 repeated uint64 F_Uint64_repeated = 26;
112 repeated float F_Float_repeated = 27;
113 repeated double F_Double_repeated = 28;
114 repeated string F_String_repeated = 29;
115 repeated bytes F_Bytes_repeated = 201;
116 repeated sint32 F_Sint32_repeated = 202;
117 repeated sint64 F_Sint64_repeated = 203;
118 repeated sfixed32 F_Sfixed32_repeated = 204;
119 repeated sfixed64 F_Sfixed64_repeated = 205;
121 // Optional fields of all basic types
122 optional bool F_Bool_optional = 30;
123 optional int32 F_Int32_optional = 31;
124 optional int64 F_Int64_optional = 32;
125 optional fixed32 F_Fixed32_optional = 33;
126 optional fixed64 F_Fixed64_optional = 34;
127 optional uint32 F_Uint32_optional = 35;
128 optional uint64 F_Uint64_optional = 36;
129 optional float F_Float_optional = 37;
130 optional double F_Double_optional = 38;
131 optional string F_String_optional = 39;
132 optional bytes F_Bytes_optional = 301;
133 optional sint32 F_Sint32_optional = 302;
134 optional sint64 F_Sint64_optional = 303;
135 optional sfixed32 F_Sfixed32_optional = 304;
136 optional sfixed64 F_Sfixed64_optional = 305;
138 // Default-valued fields of all basic types
139 optional bool F_Bool_defaulted = 40 [default=true];
140 optional int32 F_Int32_defaulted = 41 [default=32];
141 optional int64 F_Int64_defaulted = 42 [default=64];
142 optional fixed32 F_Fixed32_defaulted = 43 [default=320];
143 optional fixed64 F_Fixed64_defaulted = 44 [default=640];
144 optional uint32 F_Uint32_defaulted = 45 [default=3200];
145 optional uint64 F_Uint64_defaulted = 46 [default=6400];
146 optional float F_Float_defaulted = 47 [default=314159.];
147 optional double F_Double_defaulted = 48 [default=271828.];
148 optional string F_String_defaulted = 49 [default="hello, \"world!\"\n"];
149 optional bytes F_Bytes_defaulted = 401 [default="Bignose"];
150 optional sint32 F_Sint32_defaulted = 402 [default = -32];
151 optional sint64 F_Sint64_defaulted = 403 [default = -64];
152 optional sfixed32 F_Sfixed32_defaulted = 404 [default = -32];
153 optional sfixed64 F_Sfixed64_defaulted = 405 [default = -64];
155 // Packed repeated fields (no string or bytes).
156 repeated bool F_Bool_repeated_packed = 50 [packed=true];
157 repeated int32 F_Int32_repeated_packed = 51 [packed=true];
158 repeated int64 F_Int64_repeated_packed = 52 [packed=true];
159 repeated fixed32 F_Fixed32_repeated_packed = 53 [packed=true];
160 repeated fixed64 F_Fixed64_repeated_packed = 54 [packed=true];
161 repeated uint32 F_Uint32_repeated_packed = 55 [packed=true];
162 repeated uint64 F_Uint64_repeated_packed = 56 [packed=true];
163 repeated float F_Float_repeated_packed = 57 [packed=true];
164 repeated double F_Double_repeated_packed = 58 [packed=true];
165 repeated sint32 F_Sint32_repeated_packed = 502 [packed=true];
166 repeated sint64 F_Sint64_repeated_packed = 503 [packed=true];
167 repeated sfixed32 F_Sfixed32_repeated_packed = 504 [packed=true];
168 repeated sfixed64 F_Sfixed64_repeated_packed = 505 [packed=true];
170 // Required, repeated, and optional groups.
171 required group RequiredGroup = 70 {
172 required string RequiredField = 71;
175 repeated group RepeatedGroup = 80 {
176 required string RequiredField = 81;
179 optional group OptionalGroup = 90 {
180 required string RequiredField = 91;
184 // For testing a group containing a required field.
185 message GoTestRequiredGroupField {
186 required group Group = 1 {
187 required int32 Field = 2;
191 // For testing skipping of unrecognized fields.
192 // Numbers are all big, larger than tag numbers in GoTestField,
193 // the message used in the corresponding test.
195 required int32 skip_int32 = 11;
196 required fixed32 skip_fixed32 = 12;
197 required fixed64 skip_fixed64 = 13;
198 required string skip_string = 14;
199 required group SkipGroup = 15 {
200 required int32 group_int32 = 16;
201 required string group_string = 17;
205 // For testing packed/non-packed decoder switching.
206 // A serialized instance of one should be deserializable as the other.
207 message NonPackedTest {
208 repeated int32 a = 1;
212 repeated int32 b = 1 [packed=true];
216 // Maximum possible tag number.
217 optional string last_field = 536870911;
222 optional string name = 1;
224 optional Nested nested = 1;
226 optional int32 num = 2;
229 // NewMessage is wire compatible with OldMessage;
230 // imagine it as a future version.
233 optional string name = 1;
234 optional string food_group = 2;
236 optional Nested nested = 1;
238 // This is an int32 in OldMessage.
239 optional int64 num = 2;
242 // Smaller tests for ASCII formatting.
244 message InnerMessage {
245 required string host = 1;
246 optional int32 port = 2 [default=4000];
247 optional bool connected = 3;
250 message OtherMessage {
251 optional int64 key = 1;
252 optional bytes value = 2;
253 optional float weight = 3;
254 optional InnerMessage inner = 4;
256 extensions 100 to max;
259 message RequiredInnerMessage {
260 required InnerMessage leo_finally_won_an_oscar = 1;
264 required int32 count = 1;
265 optional string name = 2;
266 optional string quote = 3;
267 repeated string pet = 4;
268 optional InnerMessage inner = 5;
269 repeated OtherMessage others = 6;
270 optional RequiredInnerMessage we_must_go_deeper = 13;
271 repeated InnerMessage rep_inner = 12;
278 optional Color bikeshed = 7;
280 optional group SomeGroup = 8 {
281 optional int32 group_field = 9;
284 // This field becomes [][]byte in the generated code.
285 repeated bytes rep_bytes = 10;
287 optional double bigfloat = 11;
289 extensions 100 to max;
294 optional Ext more = 103;
295 optional string text = 104;
296 optional int32 number = 105;
299 optional string data = 1;
300 map<int32, int32> map_field = 2;
304 repeated string greeting = 106;
305 // leave field 200 unregistered for testing
308 message ComplexExtension {
309 optional int32 first = 1;
310 optional int32 second = 2;
311 repeated int32 third = 3;
314 extend OtherMessage {
315 optional ComplexExtension complex = 200;
316 repeated ComplexExtension r_complex = 201;
319 message DefaultsMessage {
325 extensions 100 to max;
328 extend DefaultsMessage {
329 optional double no_default_double = 101;
330 optional float no_default_float = 102;
331 optional int32 no_default_int32 = 103;
332 optional int64 no_default_int64 = 104;
333 optional uint32 no_default_uint32 = 105;
334 optional uint64 no_default_uint64 = 106;
335 optional sint32 no_default_sint32 = 107;
336 optional sint64 no_default_sint64 = 108;
337 optional fixed32 no_default_fixed32 = 109;
338 optional fixed64 no_default_fixed64 = 110;
339 optional sfixed32 no_default_sfixed32 = 111;
340 optional sfixed64 no_default_sfixed64 = 112;
341 optional bool no_default_bool = 113;
342 optional string no_default_string = 114;
343 optional bytes no_default_bytes = 115;
344 optional DefaultsMessage.DefaultsEnum no_default_enum = 116;
346 optional double default_double = 201 [default = 3.1415];
347 optional float default_float = 202 [default = 3.14];
348 optional int32 default_int32 = 203 [default = 42];
349 optional int64 default_int64 = 204 [default = 43];
350 optional uint32 default_uint32 = 205 [default = 44];
351 optional uint64 default_uint64 = 206 [default = 45];
352 optional sint32 default_sint32 = 207 [default = 46];
353 optional sint64 default_sint64 = 208 [default = 47];
354 optional fixed32 default_fixed32 = 209 [default = 48];
355 optional fixed64 default_fixed64 = 210 [default = 49];
356 optional sfixed32 default_sfixed32 = 211 [default = 50];
357 optional sfixed64 default_sfixed64 = 212 [default = 51];
358 optional bool default_bool = 213 [default = true];
359 optional string default_string = 214 [default = "Hello, string,def=foo"];
360 optional bytes default_bytes = 215 [default = "Hello, bytes"];
361 optional DefaultsMessage.DefaultsEnum default_enum = 216 [default = ONE];
364 message MyMessageSet {
365 option message_set_wire_format = true;
366 extensions 100 to max;
372 extend MyMessageSet {
373 optional Empty x201 = 201;
374 optional Empty x202 = 202;
375 optional Empty x203 = 203;
376 optional Empty x204 = 204;
377 optional Empty x205 = 205;
378 optional Empty x206 = 206;
379 optional Empty x207 = 207;
380 optional Empty x208 = 208;
381 optional Empty x209 = 209;
382 optional Empty x210 = 210;
383 optional Empty x211 = 211;
384 optional Empty x212 = 212;
385 optional Empty x213 = 213;
386 optional Empty x214 = 214;
387 optional Empty x215 = 215;
388 optional Empty x216 = 216;
389 optional Empty x217 = 217;
390 optional Empty x218 = 218;
391 optional Empty x219 = 219;
392 optional Empty x220 = 220;
393 optional Empty x221 = 221;
394 optional Empty x222 = 222;
395 optional Empty x223 = 223;
396 optional Empty x224 = 224;
397 optional Empty x225 = 225;
398 optional Empty x226 = 226;
399 optional Empty x227 = 227;
400 optional Empty x228 = 228;
401 optional Empty x229 = 229;
402 optional Empty x230 = 230;
403 optional Empty x231 = 231;
404 optional Empty x232 = 232;
405 optional Empty x233 = 233;
406 optional Empty x234 = 234;
407 optional Empty x235 = 235;
408 optional Empty x236 = 236;
409 optional Empty x237 = 237;
410 optional Empty x238 = 238;
411 optional Empty x239 = 239;
412 optional Empty x240 = 240;
413 optional Empty x241 = 241;
414 optional Empty x242 = 242;
415 optional Empty x243 = 243;
416 optional Empty x244 = 244;
417 optional Empty x245 = 245;
418 optional Empty x246 = 246;
419 optional Empty x247 = 247;
420 optional Empty x248 = 248;
421 optional Empty x249 = 249;
422 optional Empty x250 = 250;
425 message MessageList {
426 repeated group Message = 1 {
427 required string name = 2;
428 required int32 count = 3;
433 optional string string_field = 1;
434 optional bytes bytes_field = 2;
444 // Default-valued fields of all basic types.
445 // Same as GoTest, but copied here to make testing easier.
446 optional bool F_Bool = 1 [default=true];
447 optional int32 F_Int32 = 2 [default=32];
448 optional int64 F_Int64 = 3 [default=64];
449 optional fixed32 F_Fixed32 = 4 [default=320];
450 optional fixed64 F_Fixed64 = 5 [default=640];
451 optional uint32 F_Uint32 = 6 [default=3200];
452 optional uint64 F_Uint64 = 7 [default=6400];
453 optional float F_Float = 8 [default=314159.];
454 optional double F_Double = 9 [default=271828.];
455 optional string F_String = 10 [default="hello, \"world!\"\n"];
456 optional bytes F_Bytes = 11 [default="Bignose"];
457 optional sint32 F_Sint32 = 12 [default=-32];
458 optional sint64 F_Sint64 = 13 [default=-64];
459 optional Color F_Enum = 14 [default=GREEN];
461 // More fields with crazy defaults.
462 optional float F_Pinf = 15 [default=inf];
463 optional float F_Ninf = 16 [default=-inf];
464 optional float F_Nan = 17 [default=nan];
467 optional SubDefaults sub = 18;
469 // Redundant but explicit defaults.
470 optional string str_zero = 19 [default=""];
473 message SubDefaults {
474 optional int64 n = 1 [default=7];
477 message RepeatedEnum {
481 repeated Color color = 1;
484 message MoreRepeated {
485 repeated bool bools = 1;
486 repeated bool bools_packed = 2 [packed=true];
487 repeated int32 ints = 3;
488 repeated int32 ints_packed = 4 [packed=true];
489 repeated int64 int64s_packed = 7 [packed=true];
490 repeated string strings = 5;
491 repeated fixed32 fixeds = 6;
494 // GroupOld and GroupNew have the same wire format.
495 // GroupNew has a new field inside a group.
498 optional group G = 101 {
499 optional int32 x = 2;
504 optional group G = 101 {
505 optional int32 x = 2;
506 optional int32 y = 3;
510 message FloatingPoint {
511 required double f = 1;
512 optional bool exact = 2;
515 message MessageWithMap {
516 map<int32, string> name_mapping = 1;
517 map<sint64, FloatingPoint> msg_mapping = 2;
518 map<bool, bytes> byte_mapping = 3;
519 map<string, string> str_to_str = 4;
527 fixed32 F_Fixed32 = 4;
528 fixed64 F_Fixed64 = 5;
533 string F_String = 10;
535 sint32 F_Sint32 = 12;
536 sint64 F_Sint64 = 13;
537 MyMessage.Color F_Enum = 14;
538 GoTestField F_Message = 15;
540 optional int32 x = 17;
542 int32 F_Largest_Tag = 536870911;
551 optional bool make_me_cry = 1;
553 // This is a oneof, called "union".
559 MyMessage.Color col = 9;
565 optional string scalar = 1;
566 repeated string vector = 2;
567 oneof oneof { string field = 3; }
568 map<string, int64> map_key = 4;
569 map<int64, string> map_value = 5;