OSDN Git Service

Merge pull request #41 from Bytom/dev
[bytom/vapor.git] / vendor / github.com / golang / protobuf / proto / testdata / test.proto
1 // Go support for Protocol Buffers - Google's data interchange format
2 //
3 // Copyright 2010 The Go Authors.  All rights reserved.
4 // https://github.com/golang/protobuf
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
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
15 // distribution.
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.
19 //
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.
31
32 // A feature-rich test file for the protocol compiler and libraries.
33
34 syntax = "proto2";
35
36 package testdata;
37
38 enum FOO { FOO1 = 1; };
39
40 message GoEnum {
41   required FOO foo = 1;
42 }
43
44 message GoTestField {
45   required string Label = 1;
46   required string Type = 2;
47 }
48
49 message GoTest {
50   // An enum, for completeness.
51   enum KIND {
52     VOID = 0;
53
54     // Basic types
55     BOOL = 1;
56     BYTES = 2;
57     FINGERPRINT = 3;
58     FLOAT = 4;
59     INT = 5;
60     STRING = 6;
61     TIME = 7;
62
63     // Groupings
64     TUPLE = 8;
65     ARRAY = 9;
66     MAP = 10;
67
68     // Table types
69     TABLE = 11;
70
71     // Functions
72     FUNCTION = 12;  // last tag
73   };
74
75   // Some typical parameters
76   required KIND Kind = 1;
77   optional string Table = 2;
78   optional int32 Param = 3;
79
80   // Required, repeated and optional foreign fields.
81   required GoTestField RequiredField = 4;
82   repeated GoTestField RepeatedField = 5;
83   optional GoTestField OptionalField = 6;
84
85   // Required fields of all basic types
86   required bool F_Bool_required = 10;
87   required int32 F_Int32_required = 11;
88   required int64 F_Int64_required = 12;
89   required fixed32 F_Fixed32_required = 13;
90   required fixed64 F_Fixed64_required = 14;
91   required uint32 F_Uint32_required = 15;
92   required uint64 F_Uint64_required = 16;
93   required float F_Float_required = 17;
94   required double F_Double_required = 18;
95   required string F_String_required = 19;
96   required bytes F_Bytes_required = 101;
97   required sint32 F_Sint32_required = 102;
98   required sint64 F_Sint64_required = 103;
99
100   // Repeated fields of all basic types
101   repeated bool F_Bool_repeated = 20;
102   repeated int32 F_Int32_repeated = 21;
103   repeated int64 F_Int64_repeated = 22;
104   repeated fixed32 F_Fixed32_repeated = 23;
105   repeated fixed64 F_Fixed64_repeated = 24;
106   repeated uint32 F_Uint32_repeated = 25;
107   repeated uint64 F_Uint64_repeated = 26;
108   repeated float F_Float_repeated = 27;
109   repeated double F_Double_repeated = 28;
110   repeated string F_String_repeated = 29;
111   repeated bytes F_Bytes_repeated = 201;
112   repeated sint32 F_Sint32_repeated = 202;
113   repeated sint64 F_Sint64_repeated = 203;
114
115   // Optional fields of all basic types
116   optional bool F_Bool_optional = 30;
117   optional int32 F_Int32_optional = 31;
118   optional int64 F_Int64_optional = 32;
119   optional fixed32 F_Fixed32_optional = 33;
120   optional fixed64 F_Fixed64_optional = 34;
121   optional uint32 F_Uint32_optional = 35;
122   optional uint64 F_Uint64_optional = 36;
123   optional float F_Float_optional = 37;
124   optional double F_Double_optional = 38;
125   optional string F_String_optional = 39;
126   optional bytes F_Bytes_optional = 301;
127   optional sint32 F_Sint32_optional = 302;
128   optional sint64 F_Sint64_optional = 303;
129
130   // Default-valued fields of all basic types
131   optional bool F_Bool_defaulted = 40 [default=true];
132   optional int32 F_Int32_defaulted = 41 [default=32];
133   optional int64 F_Int64_defaulted = 42 [default=64];
134   optional fixed32 F_Fixed32_defaulted = 43 [default=320];
135   optional fixed64 F_Fixed64_defaulted = 44 [default=640];
136   optional uint32 F_Uint32_defaulted = 45 [default=3200];
137   optional uint64 F_Uint64_defaulted = 46 [default=6400];
138   optional float F_Float_defaulted = 47 [default=314159.];
139   optional double F_Double_defaulted = 48 [default=271828.];
140   optional string F_String_defaulted = 49 [default="hello, \"world!\"\n"];
141   optional bytes F_Bytes_defaulted = 401 [default="Bignose"];
142   optional sint32 F_Sint32_defaulted = 402 [default = -32];
143   optional sint64 F_Sint64_defaulted = 403 [default = -64];
144
145   // Packed repeated fields (no string or bytes).
146   repeated bool F_Bool_repeated_packed = 50 [packed=true];
147   repeated int32 F_Int32_repeated_packed = 51 [packed=true];
148   repeated int64 F_Int64_repeated_packed = 52 [packed=true];
149   repeated fixed32 F_Fixed32_repeated_packed = 53 [packed=true];
150   repeated fixed64 F_Fixed64_repeated_packed = 54 [packed=true];
151   repeated uint32 F_Uint32_repeated_packed = 55 [packed=true];
152   repeated uint64 F_Uint64_repeated_packed = 56 [packed=true];
153   repeated float F_Float_repeated_packed = 57 [packed=true];
154   repeated double F_Double_repeated_packed = 58 [packed=true];
155   repeated sint32 F_Sint32_repeated_packed = 502 [packed=true];
156   repeated sint64 F_Sint64_repeated_packed = 503 [packed=true];
157
158   // Required, repeated, and optional groups.
159   required group RequiredGroup = 70 {
160     required string RequiredField = 71;
161   };
162
163   repeated group RepeatedGroup = 80 {
164     required string RequiredField = 81;
165   };
166
167   optional group OptionalGroup = 90 {
168     required string RequiredField = 91;
169   };
170 }
171
172 // For testing a group containing a required field.
173 message GoTestRequiredGroupField {
174   required group Group = 1 {
175     required int32 Field = 2;
176   };
177 }
178
179 // For testing skipping of unrecognized fields.
180 // Numbers are all big, larger than tag numbers in GoTestField,
181 // the message used in the corresponding test.
182 message GoSkipTest {
183   required int32 skip_int32 = 11;
184   required fixed32 skip_fixed32 = 12;
185   required fixed64 skip_fixed64 = 13;
186   required string skip_string = 14;
187   required group SkipGroup = 15 {
188     required int32 group_int32 = 16;
189     required string group_string = 17;
190   }
191 }
192
193 // For testing packed/non-packed decoder switching.
194 // A serialized instance of one should be deserializable as the other.
195 message NonPackedTest {
196   repeated int32 a = 1;
197 }
198
199 message PackedTest {
200   repeated int32 b = 1 [packed=true];
201 }
202
203 message MaxTag {
204   // Maximum possible tag number.
205   optional string last_field = 536870911;
206 }
207
208 message OldMessage {
209   message Nested {
210     optional string name = 1;
211   }
212   optional Nested nested = 1;
213
214   optional int32 num = 2;
215 }
216
217 // NewMessage is wire compatible with OldMessage;
218 // imagine it as a future version.
219 message NewMessage {
220   message Nested {
221     optional string name = 1;
222     optional string food_group = 2;
223   }
224   optional Nested nested = 1;
225
226   // This is an int32 in OldMessage.
227   optional int64 num = 2;
228 }
229
230 // Smaller tests for ASCII formatting.
231
232 message InnerMessage {
233   required string host = 1;
234   optional int32 port = 2 [default=4000];
235   optional bool connected = 3;
236 }
237
238 message OtherMessage {
239   optional int64 key = 1;
240   optional bytes value = 2;
241   optional float weight = 3;
242   optional InnerMessage inner = 4;
243
244   extensions 100 to max;
245 }
246
247 message RequiredInnerMessage {
248   required InnerMessage leo_finally_won_an_oscar = 1;
249 }
250
251 message MyMessage {
252   required int32 count = 1;
253   optional string name = 2;
254   optional string quote = 3;
255   repeated string pet = 4;
256   optional InnerMessage inner = 5;
257   repeated OtherMessage others = 6;
258   optional RequiredInnerMessage we_must_go_deeper = 13;
259   repeated InnerMessage rep_inner = 12;
260
261   enum Color {
262     RED = 0;
263     GREEN = 1;
264     BLUE = 2;
265   };
266   optional Color bikeshed = 7;
267
268   optional group SomeGroup = 8 {
269     optional int32 group_field = 9;
270   }
271
272   // This field becomes [][]byte in the generated code.
273   repeated bytes rep_bytes = 10;
274
275   optional double bigfloat = 11;
276
277   extensions 100 to max;
278 }
279
280 message Ext {
281   extend MyMessage {
282     optional Ext more = 103;
283     optional string text = 104;
284     optional int32 number = 105;
285   }
286
287   optional string data = 1;
288 }
289
290 extend MyMessage {
291   repeated string greeting = 106;
292 }
293
294 message ComplexExtension {
295   optional int32 first = 1;
296   optional int32 second = 2;
297   repeated int32 third = 3;
298 }
299
300 extend OtherMessage {
301   optional ComplexExtension complex = 200;
302   repeated ComplexExtension r_complex = 201;
303 }
304
305 message DefaultsMessage {
306   enum DefaultsEnum {
307     ZERO = 0;
308     ONE = 1;
309     TWO = 2;
310   };
311   extensions 100 to max;
312 }
313
314 extend DefaultsMessage {
315   optional double no_default_double = 101;
316   optional float no_default_float = 102;
317   optional int32 no_default_int32 = 103;
318   optional int64 no_default_int64 = 104;
319   optional uint32 no_default_uint32 = 105;
320   optional uint64 no_default_uint64 = 106;
321   optional sint32 no_default_sint32 = 107;
322   optional sint64 no_default_sint64 = 108;
323   optional fixed32 no_default_fixed32 = 109;
324   optional fixed64 no_default_fixed64 = 110;
325   optional sfixed32 no_default_sfixed32 = 111;
326   optional sfixed64 no_default_sfixed64 = 112;
327   optional bool no_default_bool = 113;
328   optional string no_default_string = 114;
329   optional bytes no_default_bytes = 115;
330   optional DefaultsMessage.DefaultsEnum no_default_enum = 116;
331
332   optional double default_double = 201 [default = 3.1415];
333   optional float default_float = 202 [default = 3.14];
334   optional int32 default_int32 = 203 [default = 42];
335   optional int64 default_int64 = 204 [default = 43];
336   optional uint32 default_uint32 = 205 [default = 44];
337   optional uint64 default_uint64 = 206 [default = 45];
338   optional sint32 default_sint32 = 207 [default = 46];
339   optional sint64 default_sint64 = 208 [default = 47];
340   optional fixed32 default_fixed32 = 209 [default = 48];
341   optional fixed64 default_fixed64 = 210 [default = 49];
342   optional sfixed32 default_sfixed32 = 211 [default = 50];
343   optional sfixed64 default_sfixed64 = 212 [default = 51];
344   optional bool default_bool = 213 [default = true];
345   optional string default_string = 214 [default = "Hello, string"];
346   optional bytes default_bytes = 215 [default = "Hello, bytes"];
347   optional DefaultsMessage.DefaultsEnum default_enum = 216 [default = ONE];
348 }
349
350 message MyMessageSet {
351   option message_set_wire_format = true;
352   extensions 100 to max;
353 }
354
355 message Empty {
356 }
357
358 extend MyMessageSet {
359     optional Empty x201 = 201;
360     optional Empty x202 = 202;
361     optional Empty x203 = 203;
362     optional Empty x204 = 204;
363     optional Empty x205 = 205;
364     optional Empty x206 = 206;
365     optional Empty x207 = 207;
366     optional Empty x208 = 208;
367     optional Empty x209 = 209;
368     optional Empty x210 = 210;
369     optional Empty x211 = 211;
370     optional Empty x212 = 212;
371     optional Empty x213 = 213;
372     optional Empty x214 = 214;
373     optional Empty x215 = 215;
374     optional Empty x216 = 216;
375     optional Empty x217 = 217;
376     optional Empty x218 = 218;
377     optional Empty x219 = 219;
378     optional Empty x220 = 220;
379     optional Empty x221 = 221;
380     optional Empty x222 = 222;
381     optional Empty x223 = 223;
382     optional Empty x224 = 224;
383     optional Empty x225 = 225;
384     optional Empty x226 = 226;
385     optional Empty x227 = 227;
386     optional Empty x228 = 228;
387     optional Empty x229 = 229;
388     optional Empty x230 = 230;
389     optional Empty x231 = 231;
390     optional Empty x232 = 232;
391     optional Empty x233 = 233;
392     optional Empty x234 = 234;
393     optional Empty x235 = 235;
394     optional Empty x236 = 236;
395     optional Empty x237 = 237;
396     optional Empty x238 = 238;
397     optional Empty x239 = 239;
398     optional Empty x240 = 240;
399     optional Empty x241 = 241;
400     optional Empty x242 = 242;
401     optional Empty x243 = 243;
402     optional Empty x244 = 244;
403     optional Empty x245 = 245;
404     optional Empty x246 = 246;
405     optional Empty x247 = 247;
406     optional Empty x248 = 248;
407     optional Empty x249 = 249;
408     optional Empty x250 = 250;
409 }
410
411 message MessageList {
412   repeated group Message = 1 {
413     required string name = 2;
414     required int32 count = 3;
415   }
416 }
417
418 message Strings {
419   optional string string_field = 1;
420   optional bytes bytes_field = 2;
421 }
422
423 message Defaults {
424   enum Color {
425     RED = 0;
426     GREEN = 1;
427     BLUE = 2;
428   }
429
430   // Default-valued fields of all basic types.
431   // Same as GoTest, but copied here to make testing easier.
432   optional bool F_Bool = 1 [default=true];
433   optional int32 F_Int32 = 2 [default=32];
434   optional int64 F_Int64 = 3 [default=64];
435   optional fixed32 F_Fixed32 = 4 [default=320];
436   optional fixed64 F_Fixed64 = 5 [default=640];
437   optional uint32 F_Uint32 = 6 [default=3200];
438   optional uint64 F_Uint64 = 7 [default=6400];
439   optional float F_Float = 8 [default=314159.];
440   optional double F_Double = 9 [default=271828.];
441   optional string F_String = 10 [default="hello, \"world!\"\n"];
442   optional bytes F_Bytes = 11 [default="Bignose"];
443   optional sint32 F_Sint32 = 12 [default=-32];
444   optional sint64 F_Sint64 = 13 [default=-64];
445   optional Color F_Enum = 14 [default=GREEN];
446
447   // More fields with crazy defaults.
448   optional float F_Pinf = 15 [default=inf];
449   optional float F_Ninf = 16 [default=-inf];
450   optional float F_Nan = 17 [default=nan];
451
452   // Sub-message.
453   optional SubDefaults sub = 18;
454
455   // Redundant but explicit defaults.
456   optional string str_zero = 19 [default=""];
457 }
458
459 message SubDefaults {
460   optional int64 n = 1 [default=7];
461 }
462
463 message RepeatedEnum {
464   enum Color {
465     RED = 1;
466   }
467   repeated Color color = 1;
468 }
469
470 message MoreRepeated {
471   repeated bool bools = 1;
472   repeated bool bools_packed = 2 [packed=true];
473   repeated int32 ints = 3;
474   repeated int32 ints_packed = 4 [packed=true];
475   repeated int64 int64s_packed = 7 [packed=true];
476   repeated string strings = 5;
477   repeated fixed32 fixeds = 6;
478 }
479
480 // GroupOld and GroupNew have the same wire format.
481 // GroupNew has a new field inside a group.
482
483 message GroupOld {
484   optional group G = 101 {
485     optional int32 x = 2;
486   }
487 }
488
489 message GroupNew {
490   optional group G = 101 {
491     optional int32 x = 2;
492     optional int32 y = 3;
493   }
494 }
495
496 message FloatingPoint {
497   required double f = 1;
498   optional bool exact = 2;
499 }
500
501 message MessageWithMap {
502   map<int32, string> name_mapping = 1;
503   map<sint64, FloatingPoint> msg_mapping = 2;
504   map<bool, bytes> byte_mapping = 3;
505   map<string, string> str_to_str = 4;
506 }
507
508 message Oneof {
509   oneof union {
510     bool F_Bool = 1;
511     int32 F_Int32 = 2;
512     int64 F_Int64 = 3;
513     fixed32 F_Fixed32 = 4;
514     fixed64 F_Fixed64 = 5;
515     uint32 F_Uint32 = 6;
516     uint64 F_Uint64 = 7;
517     float F_Float = 8;
518     double F_Double = 9;
519     string F_String = 10;
520     bytes F_Bytes = 11;
521     sint32 F_Sint32 = 12;
522     sint64 F_Sint64 = 13;
523     MyMessage.Color F_Enum = 14;
524     GoTestField F_Message = 15;
525     group F_Group = 16 {
526       optional int32 x = 17;
527     }
528     int32 F_Largest_Tag = 536870911;
529   }
530
531   oneof tormato {
532     int32 value = 100;
533   }
534 }
535
536 message Communique {
537   optional bool make_me_cry = 1;
538
539   // This is a oneof, called "union".
540   oneof union {
541     int32 number = 5;
542     string name = 6;
543     bytes data = 7;
544     double temp_c = 8;
545     MyMessage.Color col = 9;
546     Strings msg = 10;
547   }
548 }