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