test.proto 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. // Go support for Protocol Buffers - Google's data interchange format
  2. //
  3. // Copyright 2010 Google Inc. All rights reserved.
  4. // http://code.google.com/p/goprotobuf/
  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. // A feature-rich test file for the protocol compiler and libraries.
  32. syntax = "proto2";
  33. package test_proto;
  34. enum FOO { FOO1 = 1; };
  35. message GoEnum {
  36. required FOO foo = 1;
  37. }
  38. message GoTestField {
  39. required string Label = 1;
  40. required string Type = 2;
  41. }
  42. message GoTest {
  43. // An enum, for completeness.
  44. enum KIND {
  45. VOID = 0;
  46. // Basic types
  47. BOOL = 1;
  48. BYTES = 2;
  49. FINGERPRINT = 3;
  50. FLOAT = 4;
  51. INT = 5;
  52. STRING = 6;
  53. TIME = 7;
  54. // Groupings
  55. TUPLE = 8;
  56. ARRAY = 9;
  57. MAP = 10;
  58. // Table types
  59. TABLE = 11;
  60. // Functions
  61. FUNCTION = 12; // last tag
  62. };
  63. // Some typical parameters
  64. required int32 Kind = 1;
  65. optional string Table = 2;
  66. optional int32 Param = 3;
  67. // Required, repeated and optional foreign fields.
  68. required GoTestField RequiredField = 4;
  69. repeated GoTestField RepeatedField = 5;
  70. optional GoTestField OptionalField = 6;
  71. // Required fields of all basic types
  72. required bool F_Bool_required = 10;
  73. required int32 F_Int32_required = 11;
  74. required int64 F_Int64_required = 12;
  75. required fixed32 F_Fixed32_required = 13;
  76. required fixed64 F_Fixed64_required = 14;
  77. required uint32 F_Uint32_required = 15;
  78. required uint64 F_Uint64_required = 16;
  79. required float F_Float_required = 17;
  80. required double F_Double_required = 18;
  81. required string F_String_required = 19;
  82. required bytes F_Bytes_required = 101;
  83. required sint32 F_Sint32_required = 102;
  84. required sint64 F_Sint64_required = 103;
  85. // Repeated fields of all basic types
  86. repeated bool F_Bool_repeated = 20;
  87. repeated int32 F_Int32_repeated = 21;
  88. repeated int64 F_Int64_repeated = 22;
  89. repeated fixed32 F_Fixed32_repeated = 23;
  90. repeated fixed64 F_Fixed64_repeated = 24;
  91. repeated uint32 F_Uint32_repeated = 25;
  92. repeated uint64 F_Uint64_repeated = 26;
  93. repeated float F_Float_repeated = 27;
  94. repeated double F_Double_repeated = 28;
  95. repeated string F_String_repeated = 29;
  96. repeated bytes F_Bytes_repeated = 201;
  97. repeated sint32 F_Sint32_repeated = 202;
  98. repeated sint64 F_Sint64_repeated = 203;
  99. // Optional fields of all basic types
  100. optional bool F_Bool_optional = 30;
  101. optional int32 F_Int32_optional = 31;
  102. optional int64 F_Int64_optional = 32;
  103. optional fixed32 F_Fixed32_optional = 33;
  104. optional fixed64 F_Fixed64_optional = 34;
  105. optional uint32 F_Uint32_optional = 35;
  106. optional uint64 F_Uint64_optional = 36;
  107. optional float F_Float_optional = 37;
  108. optional double F_Double_optional = 38;
  109. optional string F_String_optional = 39;
  110. optional bytes F_Bytes_optional = 301;
  111. optional sint32 F_Sint32_optional = 302;
  112. optional sint64 F_Sint64_optional = 303;
  113. // Default-valued fields of all basic types
  114. optional bool F_Bool_defaulted = 40 [default=true];
  115. optional int32 F_Int32_defaulted = 41 [default=32];
  116. optional int64 F_Int64_defaulted = 42 [default=64];
  117. optional fixed32 F_Fixed32_defaulted = 43 [default=320];
  118. optional fixed64 F_Fixed64_defaulted = 44 [default=640];
  119. optional uint32 F_Uint32_defaulted = 45 [default=3200];
  120. optional uint64 F_Uint64_defaulted = 46 [default=6400];
  121. optional float F_Float_defaulted = 47 [default=314159.];
  122. optional double F_Double_defaulted = 48 [default=271828.];
  123. optional string F_String_defaulted = 49 [default="hello, \"world!\"\n"];
  124. optional bytes F_Bytes_defaulted = 401 [default="Bignose"];
  125. optional sint32 F_Sint32_defaulted = 402 [default = -32];
  126. optional sint64 F_Sint64_defaulted = 403 [default = -64];
  127. // Required, repeated, and optional groups.
  128. required group RequiredGroup = 70 {
  129. required string RequiredField = 71;
  130. };
  131. repeated group RepeatedGroup = 80 {
  132. required string RequiredField = 81;
  133. };
  134. optional group OptionalGroup = 90 {
  135. required string RequiredField = 91;
  136. };
  137. };
  138. // For testing skipping of unrecognized fields.
  139. // Numbers are all big, larger than tag numbers in GoTestField,
  140. // the message used in the corresponding test.
  141. message GoSkipTest {
  142. required int32 skip_int32 = 11;
  143. required fixed32 skip_fixed32 = 12;
  144. required fixed64 skip_fixed64 = 13;
  145. required string skip_string = 14;
  146. required group SkipGroup = 15 {
  147. required int32 group_int32 = 16;
  148. required string group_string = 17;
  149. }
  150. }
  151. // Smaller tests for ASCII formatting.
  152. message InnerMessage {
  153. required string host = 1;
  154. optional int32 port = 2 [default=4000];
  155. optional bool connected = 3;
  156. }
  157. message OtherMessage {
  158. optional int64 key = 1;
  159. optional bytes value = 2;
  160. optional float weight = 3;
  161. optional InnerMessage inner = 4;
  162. }
  163. message MyMessage {
  164. required int32 count = 1;
  165. optional string name = 2;
  166. optional string quote = 3;
  167. repeated string pet = 4;
  168. optional InnerMessage inner = 5;
  169. repeated OtherMessage others = 6;
  170. enum Color {
  171. RED = 0;
  172. GREEN = 1;
  173. BLUE = 2;
  174. };
  175. optional Color bikeshed = 7;
  176. }
  177. message MessageList {
  178. repeated group Message = 1 {
  179. required string name = 2;
  180. required int32 count = 3;
  181. };
  182. };