blob: 861dd24ff16d598c39af01faafc7a2c727c1564f [file] [log] [blame]
Herbie Ongcddf8192018-11-28 18:25:20 -08001// Copyright 2018 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
5// Test Protobuf definitions with proto2 syntax.
6syntax = "proto2";
7
8package pb2;
9option go_package = "github.com/golang/protobuf/v2/encoding/textpb/testprotos/pb2";
10
11import "google/protobuf/any.proto";
12import "google/protobuf/empty.proto";
13import "google/protobuf/duration.proto";
14import "google/protobuf/struct.proto";
15import "google/protobuf/timestamp.proto";
16import "google/protobuf/wrappers.proto";
17
18// Scalars contains optional scalar fields.
19message Scalars {
20 optional bool opt_bool = 1;
21
22 optional int32 opt_int32 = 2;
23 optional int64 opt_int64 = 3;
24 optional uint32 opt_uint32 = 4;
25 optional uint64 opt_uint64 = 5;
26 optional sint32 opt_sint32 = 6;
27 optional sint64 opt_sint64 = 7;
28 optional fixed32 opt_fixed32 = 8;
29 optional fixed64 opt_fixed64 = 9;
30 optional sfixed32 opt_sfixed32 = 10;
31 optional sfixed64 opt_sfixed64 = 11;
32
33 optional float opt_float = 20;
34 optional double opt_double = 21;
35
36 optional bytes opt_bytes = 14;
37 optional string opt_string = 13;
38}
39
40// Message contains repeated fields.
41message Repeats {
42 repeated bool rpt_bool = 1;
43 repeated int32 rpt_int32 = 2;
44 repeated int64 rpt_int64 = 3;
45 repeated uint32 rpt_uint32 = 4;
46 repeated uint64 rpt_uint64 = 5;
47 repeated float rpt_float = 6;
48 repeated double rpt_double = 7;
49 repeated string rpt_string = 15;
50 repeated bytes rpt_bytes = 14;
51}
52
53enum Enum {
54 UNKNOWN = 0;
55 FIRST = 1;
56 SECOND = 2;
57 TENTH = 10;
58}
59
60// Message contains enum fields.
61message Enums {
62 optional Enum opt_enum = 1;
63 repeated Enum rpt_enum = 2;
64
65 enum NestedEnum {
66 UNO = 1;
67 DOS = 2;
68 DIEZ = 10;
69 }
70 optional NestedEnum opt_nested_enum = 3;
71 repeated NestedEnum rpt_nested_enum = 4;
72}
73
74// Message contains message and group fields.
75message Nests {
76 optional Nested opt_nested = 1;
77 optional group OptGroup = 2 {
78 optional bool opt_bool = 1;
79 optional string opt_string = 2;
80 optional Nested opt_nested = 3;
81
82 optional group OptNestedGroup = 4 {
83 optional Enum opt_enum = 1;
84 }
85 }
86
87 repeated Nested rpt_nested = 3;
88 repeated group RptGroup = 4 {
89 repeated bool rpt_bool = 1;
90 }
Herbie Ong7c624e22018-12-13 14:41:22 -080091
92 reserved "reserved_field";
Herbie Ongcddf8192018-11-28 18:25:20 -080093}
94
95// Message type used as submessage.
96message Nested {
97 optional string opt_string = 1;
98 optional Nested opt_nested = 2;
99}
100
101// Message contains required fields.
102message Requireds {
103 required bool req_bool = 1;
104 required fixed32 req_fixed32 = 2;
105 required fixed64 req_fixed64 = 3;
106 required sfixed32 req_sfixed32 = 4;
107 required sfixed64 req_sfixed64 = 5;
108 required float req_float = 6;
109 required double req_double = 7;
110 required string req_string = 8;
111 required bytes req_bytes = 9;
112 required Enum req_enum = 10;
113 required Nested req_nested = 11;
114}
115
Herbie Ong800c9902018-12-06 15:28:53 -0800116// Message contains both required and optional fields.
117message PartialRequired {
118 required string req_string = 1;
119 optional string opt_string = 2;
120}
121
Herbie Ongcddf8192018-11-28 18:25:20 -0800122// Message contains oneof field.
123message Oneofs {
124 oneof union {
125 string str = 1;
126 Nested msg = 2;
127 }
128}
129
130// Message contains map fields.
131message Maps {
132 map<int32, string> int32_to_str = 1;
133 map<sfixed64, bool> sfixed64_to_bool = 2;
134 map<bool, uint32> bool_to_uint32 = 3;
135 map<uint64, Enum> uint64_to_enum = 4;
136 map<string, Nested> str_to_nested = 5;
137 map<string, Oneofs> str_to_oneofs = 6;
138}
139
Herbie Ong800c9902018-12-06 15:28:53 -0800140// Following messages are for testing required field nested in optional, repeated and map fields.
Herbie Ongcf253082018-12-17 17:13:07 -0800141
Herbie Ong800c9902018-12-06 15:28:53 -0800142message NestedWithRequired {
143 required string req_string = 1;
144}
145
146message IndirectRequired {
147 optional NestedWithRequired opt_nested = 1;
148 repeated NestedWithRequired rpt_nested = 2;
149 map<string, NestedWithRequired> str_to_nested = 3;
150}
151
Herbie Ongcf253082018-12-17 17:13:07 -0800152// Following messages are for testing extensions.
153
154message Extensions {
155 optional string opt_string = 1;
156 extensions 20 to 100;
157 optional bool opt_bool = 101;
158 optional int32 opt_int32 = 2;
159}
160
161extend Extensions {
162 optional bool opt_ext_bool = 21;
163 optional string opt_ext_string = 22;
164 optional Enum opt_ext_enum = 23;
165 optional Nested opt_ext_nested = 24;
166
167 repeated fixed32 rpt_ext_fixed32 = 31;
168 repeated Enum rpt_ext_enum = 32;
169 repeated Nested rpt_ext_nested = 33;
170}
171
172message ExtensionsContainer {
173 extend Extensions {
174 optional bool opt_ext_bool = 51;
175 optional string opt_ext_string = 52;
176 optional Enum opt_ext_enum = 53;
177 optional Nested opt_ext_nested = 54;
178
179 repeated string rpt_ext_string = 61;
180 repeated Enum rpt_ext_enum = 62;
181 repeated Nested rpt_ext_nested = 63;
182 }
183}
184
185// Following messages are for testing MessageSet.
186
187message MessageSet {
188 option message_set_wire_format = true;
189
190 extensions 4 to max;
191}
192
193message MessageSetExtension {
194 optional string opt_string = 1;
195
196 extend MessageSet {
197 optional MessageSetExtension message_set_extension = 10;
198 optional MessageSetExtension not_message_set_extension = 20;
199 optional Nested ext_nested = 30;
200 }
201}
202
Herbie Ongcddf8192018-11-28 18:25:20 -0800203// Message contains well-known type fields.
204message KnownTypes {
205 optional google.protobuf.BoolValue opt_bool = 1;
206 optional google.protobuf.Int32Value opt_int32 = 2;
207 optional google.protobuf.Int64Value opt_int64 = 3;
208 optional google.protobuf.UInt32Value opt_uint32 = 4;
209 optional google.protobuf.UInt64Value opt_uint64 = 5;
210 optional google.protobuf.FloatValue opt_float = 6;
211 optional google.protobuf.DoubleValue opt_double = 7;
212 optional google.protobuf.StringValue opt_string = 8;
213 optional google.protobuf.BytesValue opt_bytes = 9;
214
215 optional google.protobuf.Duration opt_duration = 20;
216 optional google.protobuf.Timestamp opt_timestamp = 21;
217 optional google.protobuf.Struct opt_struct = 25;
218 optional google.protobuf.ListValue opt_list = 26;
219 optional google.protobuf.Value opt_value = 27;
220 optional google.protobuf.Empty opt_empty = 30;
221 optional google.protobuf.Any opt_any = 32;
222}