test.proto 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. // Copyright 2019 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Test Protobuf definitions with proto2 syntax.
  5. syntax = "proto2";
  6. package pb2;
  7. option go_package = "google.golang.org/protobuf/encoding/testprotos/pb2";
  8. import "google/protobuf/any.proto";
  9. import "google/protobuf/empty.proto";
  10. import "google/protobuf/field_mask.proto";
  11. import "google/protobuf/duration.proto";
  12. import "google/protobuf/struct.proto";
  13. import "google/protobuf/timestamp.proto";
  14. import "google/protobuf/wrappers.proto";
  15. // Scalars contains optional scalar fields.
  16. message Scalars {
  17. optional bool opt_bool = 1;
  18. optional int32 opt_int32 = 2;
  19. optional int64 opt_int64 = 3;
  20. optional uint32 opt_uint32 = 4;
  21. optional uint64 opt_uint64 = 5;
  22. optional sint32 opt_sint32 = 6;
  23. optional sint64 opt_sint64 = 7;
  24. optional fixed32 opt_fixed32 = 8;
  25. optional fixed64 opt_fixed64 = 9;
  26. optional sfixed32 opt_sfixed32 = 10;
  27. optional sfixed64 opt_sfixed64 = 11;
  28. // Textproto marshal outputs fields in the same order as this proto
  29. // definition regardless of field number. Following fields are intended to
  30. // test that assumption.
  31. optional float opt_float = 20;
  32. optional double opt_double = 21;
  33. optional bytes opt_bytes = 14;
  34. optional string opt_string = 13;
  35. }
  36. enum Enum {
  37. ONE = 1;
  38. TWO = 2;
  39. TEN = 10;
  40. }
  41. // Message contains enum fields.
  42. message Enums {
  43. optional Enum opt_enum = 1;
  44. repeated Enum rpt_enum = 2;
  45. enum NestedEnum {
  46. UNO = 1;
  47. DOS = 2;
  48. DIEZ = 10;
  49. }
  50. optional NestedEnum opt_nested_enum = 3;
  51. repeated NestedEnum rpt_nested_enum = 4;
  52. }
  53. // Message contains repeated fields.
  54. message Repeats {
  55. repeated bool rpt_bool = 1;
  56. repeated int32 rpt_int32 = 2;
  57. repeated int64 rpt_int64 = 3;
  58. repeated uint32 rpt_uint32 = 4;
  59. repeated uint64 rpt_uint64 = 5;
  60. repeated float rpt_float = 6;
  61. repeated double rpt_double = 7;
  62. repeated string rpt_string = 8;
  63. repeated bytes rpt_bytes = 9;
  64. }
  65. // Message type used as submessage.
  66. message Nested {
  67. optional string opt_string = 1;
  68. optional Nested opt_nested = 2;
  69. }
  70. // Message contains message and group fields.
  71. message Nests {
  72. optional Nested opt_nested = 1;
  73. optional group OptGroup = 2 {
  74. optional string opt_string = 1;
  75. optional Nested opt_nested = 2;
  76. optional group OptNestedGroup = 3 {
  77. optional fixed32 opt_fixed32 = 1;
  78. }
  79. }
  80. repeated Nested rpt_nested = 4;
  81. repeated group RptGroup = 5 {
  82. repeated string rpt_string = 1;
  83. }
  84. reserved "reserved_field";
  85. }
  86. // Message contains required fields.
  87. message Requireds {
  88. required bool req_bool = 1;
  89. required sfixed64 req_sfixed64 = 2;
  90. required double req_double = 3;
  91. required string req_string = 4;
  92. required Enum req_enum = 5;
  93. required Nested req_nested = 6;
  94. }
  95. // Message contains both required and optional fields.
  96. message PartialRequired {
  97. required string req_string = 1;
  98. optional string opt_string = 2;
  99. }
  100. // Following messages are for testing required field nested in optional, repeated and map fields.
  101. message NestedWithRequired {
  102. required string req_string = 1;
  103. }
  104. message IndirectRequired {
  105. optional NestedWithRequired opt_nested = 1;
  106. repeated NestedWithRequired rpt_nested = 2;
  107. map<string, NestedWithRequired> str_to_nested = 3;
  108. oneof union {
  109. NestedWithRequired oneof_nested = 4;
  110. }
  111. }
  112. // Following messages are for testing extensions.
  113. message Extensions {
  114. optional string opt_string = 1;
  115. extensions 20 to 100;
  116. optional bool opt_bool = 101;
  117. optional int32 opt_int32 = 2;
  118. }
  119. extend Extensions {
  120. optional bool opt_ext_bool = 21;
  121. optional string opt_ext_string = 22;
  122. optional Enum opt_ext_enum = 23;
  123. optional Nested opt_ext_nested = 24;
  124. optional PartialRequired opt_ext_partial = 25;
  125. repeated fixed32 rpt_ext_fixed32 = 31;
  126. repeated Enum rpt_ext_enum = 32;
  127. repeated Nested rpt_ext_nested = 33;
  128. }
  129. message ExtensionsContainer {
  130. extend Extensions {
  131. optional bool opt_ext_bool = 51;
  132. optional string opt_ext_string = 52;
  133. optional Enum opt_ext_enum = 53;
  134. optional Nested opt_ext_nested = 54;
  135. optional PartialRequired opt_ext_partial = 55;
  136. repeated string rpt_ext_string = 61;
  137. repeated Enum rpt_ext_enum = 62;
  138. repeated Nested rpt_ext_nested = 63;
  139. }
  140. }
  141. // Following messages are for testing MessageSet.
  142. message MessageSet {
  143. option message_set_wire_format = true;
  144. extensions 4 to max;
  145. }
  146. message MessageSetExtension {
  147. optional string opt_string = 1;
  148. extend MessageSet {
  149. optional MessageSetExtension message_set_extension = 10;
  150. optional MessageSetExtension not_message_set_extension = 20;
  151. optional Nested ext_nested = 30;
  152. }
  153. }
  154. message FakeMessageSet {
  155. extensions 4 to max;
  156. }
  157. message FakeMessageSetExtension {
  158. optional string opt_string = 1;
  159. extend FakeMessageSet {
  160. optional FakeMessageSetExtension message_set_extension = 10;
  161. }
  162. }
  163. extend MessageSet {
  164. optional FakeMessageSetExtension message_set_extension = 50;
  165. }
  166. // Message contains well-known type fields.
  167. message KnownTypes {
  168. optional google.protobuf.BoolValue opt_bool = 1;
  169. optional google.protobuf.Int32Value opt_int32 = 2;
  170. optional google.protobuf.Int64Value opt_int64 = 3;
  171. optional google.protobuf.UInt32Value opt_uint32 = 4;
  172. optional google.protobuf.UInt64Value opt_uint64 = 5;
  173. optional google.protobuf.FloatValue opt_float = 6;
  174. optional google.protobuf.DoubleValue opt_double = 7;
  175. optional google.protobuf.StringValue opt_string = 8;
  176. optional google.protobuf.BytesValue opt_bytes = 9;
  177. optional google.protobuf.Duration opt_duration = 20;
  178. optional google.protobuf.Timestamp opt_timestamp = 21;
  179. optional google.protobuf.Struct opt_struct = 25;
  180. optional google.protobuf.ListValue opt_list = 26;
  181. optional google.protobuf.Value opt_value = 27;
  182. optional google.protobuf.NullValue opt_null = 28;
  183. optional google.protobuf.Empty opt_empty = 30;
  184. optional google.protobuf.Any opt_any = 32;
  185. optional google.protobuf.FieldMask opt_fieldmask = 40;
  186. }