blob: d41583a56c8da4aa39464aa11e25d292ca4a0735 [file] [log] [blame]
Herbie Ong8170d692019-02-13 14:13:21 -08001// Copyright 2019 The Go Authors. All rights reserved.
Herbie Ongcddf8192018-11-28 18:25:20 -08002// 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;
Herbie Ong8170d692019-02-13 14:13:21 -08009option go_package = "github.com/golang/protobuf/v2/encoding/testprotos/pb2";
Herbie Ongcddf8192018-11-28 18:25:20 -080010
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;
Herbie Ongcddf8192018-11-28 18:25:20 -080021 optional int32 opt_int32 = 2;
22 optional int64 opt_int64 = 3;
23 optional uint32 opt_uint32 = 4;
24 optional uint64 opt_uint64 = 5;
25 optional sint32 opt_sint32 = 6;
26 optional sint64 opt_sint64 = 7;
27 optional fixed32 opt_fixed32 = 8;
28 optional fixed64 opt_fixed64 = 9;
29 optional sfixed32 opt_sfixed32 = 10;
30 optional sfixed64 opt_sfixed64 = 11;
31
Herbie Ong8170d692019-02-13 14:13:21 -080032 // Textproto marshal outputs fields in the same order as this proto
33 // definition regardless of field number. Following fields are intended to
34 // test that assumption.
35
Herbie Ongcddf8192018-11-28 18:25:20 -080036 optional float opt_float = 20;
37 optional double opt_double = 21;
38
39 optional bytes opt_bytes = 14;
40 optional string opt_string = 13;
41}
42
Herbie Ongcddf8192018-11-28 18:25:20 -080043enum Enum {
Herbie Ong8170d692019-02-13 14:13:21 -080044 ONE = 1;
45 TWO = 2;
46 TEN = 10;
Herbie Ongcddf8192018-11-28 18:25:20 -080047}
48
49// Message contains enum fields.
50message Enums {
51 optional Enum opt_enum = 1;
52 repeated Enum rpt_enum = 2;
53
54 enum NestedEnum {
55 UNO = 1;
56 DOS = 2;
57 DIEZ = 10;
58 }
59 optional NestedEnum opt_nested_enum = 3;
60 repeated NestedEnum rpt_nested_enum = 4;
61}
62
Herbie Ong8170d692019-02-13 14:13:21 -080063// Message contains repeated fields.
64message Repeats {
65 repeated bool rpt_bool = 1;
66 repeated int32 rpt_int32 = 2;
67 repeated int64 rpt_int64 = 3;
68 repeated uint32 rpt_uint32 = 4;
69 repeated uint64 rpt_uint64 = 5;
70 repeated float rpt_float = 6;
71 repeated double rpt_double = 7;
72 repeated string rpt_string = 8;
73 repeated bytes rpt_bytes = 9;
Herbie Ongcddf8192018-11-28 18:25:20 -080074}
75
76// Message type used as submessage.
77message Nested {
78 optional string opt_string = 1;
79 optional Nested opt_nested = 2;
80}
81
Herbie Ong8170d692019-02-13 14:13:21 -080082// Message contains message and group fields.
83message Nests {
84 optional Nested opt_nested = 1;
85 optional group OptGroup = 2 {
86 optional string opt_string = 1;
87 optional Nested opt_nested = 2;
88
89 optional group OptNestedGroup = 3 {
90 optional fixed32 opt_fixed32 = 1;
91 }
92 }
93
94 repeated Nested rpt_nested = 4;
95 repeated group RptGroup = 5 {
96 repeated string rpt_string = 1;
97 }
98
99 reserved "reserved_field";
100}
101
Herbie Ongcddf8192018-11-28 18:25:20 -0800102// Message contains required fields.
103message Requireds {
104 required bool req_bool = 1;
Herbie Ong8170d692019-02-13 14:13:21 -0800105 required sfixed64 req_sfixed64 = 2;
106 required double req_double = 3;
107 required string req_string = 4;
108 required Enum req_enum = 5;
109 required Nested req_nested = 6;
Herbie Ongcddf8192018-11-28 18:25:20 -0800110}
111
Herbie Ong800c9902018-12-06 15:28:53 -0800112// Message contains both required and optional fields.
113message PartialRequired {
114 required string req_string = 1;
115 optional string opt_string = 2;
116}
117
Herbie Ong800c9902018-12-06 15:28:53 -0800118// Following messages are for testing required field nested in optional, repeated and map fields.
Herbie Ongcf253082018-12-17 17:13:07 -0800119
Herbie Ong800c9902018-12-06 15:28:53 -0800120message NestedWithRequired {
121 required string req_string = 1;
122}
123
124message IndirectRequired {
125 optional NestedWithRequired opt_nested = 1;
126 repeated NestedWithRequired rpt_nested = 2;
127 map<string, NestedWithRequired> str_to_nested = 3;
Herbie Ong8170d692019-02-13 14:13:21 -0800128
129 oneof union {
130 NestedWithRequired oneof_nested = 4;
131 }
Herbie Ong800c9902018-12-06 15:28:53 -0800132}
133
Herbie Ongcf253082018-12-17 17:13:07 -0800134// Following messages are for testing extensions.
135
136message Extensions {
137 optional string opt_string = 1;
138 extensions 20 to 100;
139 optional bool opt_bool = 101;
140 optional int32 opt_int32 = 2;
141}
142
143extend Extensions {
144 optional bool opt_ext_bool = 21;
145 optional string opt_ext_string = 22;
146 optional Enum opt_ext_enum = 23;
147 optional Nested opt_ext_nested = 24;
148
149 repeated fixed32 rpt_ext_fixed32 = 31;
150 repeated Enum rpt_ext_enum = 32;
151 repeated Nested rpt_ext_nested = 33;
152}
153
154message ExtensionsContainer {
155 extend Extensions {
156 optional bool opt_ext_bool = 51;
157 optional string opt_ext_string = 52;
158 optional Enum opt_ext_enum = 53;
159 optional Nested opt_ext_nested = 54;
160
161 repeated string rpt_ext_string = 61;
162 repeated Enum rpt_ext_enum = 62;
163 repeated Nested rpt_ext_nested = 63;
164 }
165}
166
167// Following messages are for testing MessageSet.
168
169message MessageSet {
170 option message_set_wire_format = true;
171
172 extensions 4 to max;
173}
174
175message MessageSetExtension {
176 optional string opt_string = 1;
177
178 extend MessageSet {
179 optional MessageSetExtension message_set_extension = 10;
180 optional MessageSetExtension not_message_set_extension = 20;
181 optional Nested ext_nested = 30;
182 }
183}
184
Herbie Ong6470ea62019-01-07 18:56:57 -0800185message FakeMessageSet {
186 extensions 4 to max;
187}
188
189message FakeMessageSetExtension {
190 optional string opt_string = 1;
191
192 extend FakeMessageSet {
193 optional FakeMessageSetExtension message_set_extension = 10;
194 }
195}
196
197extend MessageSet {
198 optional FakeMessageSetExtension message_set_extension = 50;
199}
200
Herbie Ongcddf8192018-11-28 18:25:20 -0800201// Message contains well-known type fields.
202message KnownTypes {
203 optional google.protobuf.BoolValue opt_bool = 1;
204 optional google.protobuf.Int32Value opt_int32 = 2;
205 optional google.protobuf.Int64Value opt_int64 = 3;
206 optional google.protobuf.UInt32Value opt_uint32 = 4;
207 optional google.protobuf.UInt64Value opt_uint64 = 5;
208 optional google.protobuf.FloatValue opt_float = 6;
209 optional google.protobuf.DoubleValue opt_double = 7;
210 optional google.protobuf.StringValue opt_string = 8;
211 optional google.protobuf.BytesValue opt_bytes = 9;
212
213 optional google.protobuf.Duration opt_duration = 20;
214 optional google.protobuf.Timestamp opt_timestamp = 21;
215 optional google.protobuf.Struct opt_struct = 25;
216 optional google.protobuf.ListValue opt_list = 26;
217 optional google.protobuf.Value opt_value = 27;
218 optional google.protobuf.Empty opt_empty = 30;
219 optional google.protobuf.Any opt_any = 32;
220}