Herbie Ong | 8170d69 | 2019-02-13 14:13:21 -0800 | [diff] [blame^] | 1 | // Copyright 2019 The Go Authors. All rights reserved. |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 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. |
| 6 | syntax = "proto2"; |
| 7 | |
| 8 | package pb2; |
Herbie Ong | 8170d69 | 2019-02-13 14:13:21 -0800 | [diff] [blame^] | 9 | option go_package = "github.com/golang/protobuf/v2/encoding/testprotos/pb2"; |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 10 | |
| 11 | import "google/protobuf/any.proto"; |
| 12 | import "google/protobuf/empty.proto"; |
| 13 | import "google/protobuf/duration.proto"; |
| 14 | import "google/protobuf/struct.proto"; |
| 15 | import "google/protobuf/timestamp.proto"; |
| 16 | import "google/protobuf/wrappers.proto"; |
| 17 | |
| 18 | // Scalars contains optional scalar fields. |
| 19 | message Scalars { |
| 20 | optional bool opt_bool = 1; |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 21 | 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 Ong | 8170d69 | 2019-02-13 14:13:21 -0800 | [diff] [blame^] | 32 | // 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 Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 36 | 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 Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 43 | enum Enum { |
Herbie Ong | 8170d69 | 2019-02-13 14:13:21 -0800 | [diff] [blame^] | 44 | ONE = 1; |
| 45 | TWO = 2; |
| 46 | TEN = 10; |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | // Message contains enum fields. |
| 50 | message 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 Ong | 8170d69 | 2019-02-13 14:13:21 -0800 | [diff] [blame^] | 63 | // Message contains repeated fields. |
| 64 | message 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 Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | // Message type used as submessage. |
| 77 | message Nested { |
| 78 | optional string opt_string = 1; |
| 79 | optional Nested opt_nested = 2; |
| 80 | } |
| 81 | |
Herbie Ong | 8170d69 | 2019-02-13 14:13:21 -0800 | [diff] [blame^] | 82 | // Message contains message and group fields. |
| 83 | message 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 Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 102 | // Message contains required fields. |
| 103 | message Requireds { |
| 104 | required bool req_bool = 1; |
Herbie Ong | 8170d69 | 2019-02-13 14:13:21 -0800 | [diff] [blame^] | 105 | 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 Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 110 | } |
| 111 | |
Herbie Ong | 800c990 | 2018-12-06 15:28:53 -0800 | [diff] [blame] | 112 | // Message contains both required and optional fields. |
| 113 | message PartialRequired { |
| 114 | required string req_string = 1; |
| 115 | optional string opt_string = 2; |
| 116 | } |
| 117 | |
Herbie Ong | 800c990 | 2018-12-06 15:28:53 -0800 | [diff] [blame] | 118 | // Following messages are for testing required field nested in optional, repeated and map fields. |
Herbie Ong | cf25308 | 2018-12-17 17:13:07 -0800 | [diff] [blame] | 119 | |
Herbie Ong | 800c990 | 2018-12-06 15:28:53 -0800 | [diff] [blame] | 120 | message NestedWithRequired { |
| 121 | required string req_string = 1; |
| 122 | } |
| 123 | |
| 124 | message IndirectRequired { |
| 125 | optional NestedWithRequired opt_nested = 1; |
| 126 | repeated NestedWithRequired rpt_nested = 2; |
| 127 | map<string, NestedWithRequired> str_to_nested = 3; |
Herbie Ong | 8170d69 | 2019-02-13 14:13:21 -0800 | [diff] [blame^] | 128 | |
| 129 | oneof union { |
| 130 | NestedWithRequired oneof_nested = 4; |
| 131 | } |
Herbie Ong | 800c990 | 2018-12-06 15:28:53 -0800 | [diff] [blame] | 132 | } |
| 133 | |
Herbie Ong | cf25308 | 2018-12-17 17:13:07 -0800 | [diff] [blame] | 134 | // Following messages are for testing extensions. |
| 135 | |
| 136 | message 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 | |
| 143 | extend 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 | |
| 154 | message 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 | |
| 169 | message MessageSet { |
| 170 | option message_set_wire_format = true; |
| 171 | |
| 172 | extensions 4 to max; |
| 173 | } |
| 174 | |
| 175 | message 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 Ong | 6470ea6 | 2019-01-07 18:56:57 -0800 | [diff] [blame] | 185 | message FakeMessageSet { |
| 186 | extensions 4 to max; |
| 187 | } |
| 188 | |
| 189 | message FakeMessageSetExtension { |
| 190 | optional string opt_string = 1; |
| 191 | |
| 192 | extend FakeMessageSet { |
| 193 | optional FakeMessageSetExtension message_set_extension = 10; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | extend MessageSet { |
| 198 | optional FakeMessageSetExtension message_set_extension = 50; |
| 199 | } |
| 200 | |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 201 | // Message contains well-known type fields. |
| 202 | message 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 | } |