test.proto 5.6 KB

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