blob: cd20cc5f123f7584cca680f57884717f275f62b0 [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 }
91}
92
93// Message type used as submessage.
94message Nested {
95 optional string opt_string = 1;
96 optional Nested opt_nested = 2;
97}
98
99// Message contains required fields.
100message Requireds {
101 required bool req_bool = 1;
102 required fixed32 req_fixed32 = 2;
103 required fixed64 req_fixed64 = 3;
104 required sfixed32 req_sfixed32 = 4;
105 required sfixed64 req_sfixed64 = 5;
106 required float req_float = 6;
107 required double req_double = 7;
108 required string req_string = 8;
109 required bytes req_bytes = 9;
110 required Enum req_enum = 10;
111 required Nested req_nested = 11;
112}
113
Herbie Ong800c9902018-12-06 15:28:53 -0800114// Message contains both required and optional fields.
115message PartialRequired {
116 required string req_string = 1;
117 optional string opt_string = 2;
118}
119
Herbie Ongcddf8192018-11-28 18:25:20 -0800120// Message contains oneof field.
121message Oneofs {
122 oneof union {
123 string str = 1;
124 Nested msg = 2;
125 }
126}
127
128// Message contains map fields.
129message Maps {
130 map<int32, string> int32_to_str = 1;
131 map<sfixed64, bool> sfixed64_to_bool = 2;
132 map<bool, uint32> bool_to_uint32 = 3;
133 map<uint64, Enum> uint64_to_enum = 4;
134 map<string, Nested> str_to_nested = 5;
135 map<string, Oneofs> str_to_oneofs = 6;
136}
137
Herbie Ong800c9902018-12-06 15:28:53 -0800138// Following messages are for testing required field nested in optional, repeated and map fields.
139message NestedWithRequired {
140 required string req_string = 1;
141}
142
143message IndirectRequired {
144 optional NestedWithRequired opt_nested = 1;
145 repeated NestedWithRequired rpt_nested = 2;
146 map<string, NestedWithRequired> str_to_nested = 3;
147}
148
Herbie Ongcddf8192018-11-28 18:25:20 -0800149// Message contains well-known type fields.
150message KnownTypes {
151 optional google.protobuf.BoolValue opt_bool = 1;
152 optional google.protobuf.Int32Value opt_int32 = 2;
153 optional google.protobuf.Int64Value opt_int64 = 3;
154 optional google.protobuf.UInt32Value opt_uint32 = 4;
155 optional google.protobuf.UInt64Value opt_uint64 = 5;
156 optional google.protobuf.FloatValue opt_float = 6;
157 optional google.protobuf.DoubleValue opt_double = 7;
158 optional google.protobuf.StringValue opt_string = 8;
159 optional google.protobuf.BytesValue opt_bytes = 9;
160
161 optional google.protobuf.Duration opt_duration = 20;
162 optional google.protobuf.Timestamp opt_timestamp = 21;
163 optional google.protobuf.Struct opt_struct = 25;
164 optional google.protobuf.ListValue opt_list = 26;
165 optional google.protobuf.Value opt_value = 27;
166 optional google.protobuf.Empty opt_empty = 30;
167 optional google.protobuf.Any opt_any = 32;
168}