Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 1 | // Protocol Buffers - Google's data interchange format |
| 2 | // Copyright 2008 Google Inc. All rights reserved. |
| 3 | // https://developers.google.com/protocol-buffers/ |
| 4 | // |
| 5 | // Redistribution and use in source and binary forms, with or without |
| 6 | // modification, are permitted provided that the following conditions are |
| 7 | // met: |
| 8 | // |
| 9 | // * Redistributions of source code must retain the above copyright |
| 10 | // notice, this list of conditions and the following disclaimer. |
| 11 | // * Redistributions in binary form must reproduce the above |
| 12 | // copyright notice, this list of conditions and the following disclaimer |
| 13 | // in the documentation and/or other materials provided with the |
| 14 | // distribution. |
| 15 | // * Neither the name of Google Inc. nor the names of its |
| 16 | // contributors may be used to endorse or promote products derived from |
| 17 | // this software without specific prior written permission. |
| 18 | // |
| 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | |
Paul Yang | 7bff839 | 2019-07-19 14:49:01 -0700 | [diff] [blame] | 31 | // LINT: LEGACY_NAMES |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 32 | // Author: mwr@google.com (Mark Rawling) |
| 33 | |
| 34 | syntax = "proto2"; |
| 35 | |
| 36 | option java_package = "com.google.apps.jspb.proto"; |
| 37 | option java_multiple_files = true; |
| 38 | |
| 39 | import "google/protobuf/descriptor.proto"; |
| 40 | |
| 41 | package jspb.test; |
| 42 | |
Yilun Chong | cb95a7f | 2019-01-11 11:40:52 -0800 | [diff] [blame] | 43 | message Empty {} |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 44 | |
| 45 | enum OuterEnum { |
| 46 | FOO = 1; |
| 47 | BAR = 2; |
| 48 | } |
| 49 | |
| 50 | message EnumContainer { |
| 51 | optional OuterEnum outer_enum = 1; |
| 52 | } |
| 53 | |
| 54 | message Simple1 { |
| 55 | required string a_string = 1; |
| 56 | repeated string a_repeated_string = 2; |
| 57 | optional bool a_boolean = 3; |
| 58 | } |
| 59 | |
| 60 | // A message that differs from Simple1 only by name |
| 61 | message Simple2 { |
| 62 | required string a_string = 1; |
| 63 | repeated string a_repeated_string = 2; |
| 64 | } |
| 65 | |
| 66 | message SpecialCases { |
| 67 | required string normal = 1; |
| 68 | // Examples of Js reserved names that are converted to pb_<name>. |
| 69 | required string default = 2; |
| 70 | required string function = 3; |
| 71 | required string var = 4; |
| 72 | } |
| 73 | |
| 74 | message OptionalFields { |
| 75 | message Nested { |
| 76 | optional int32 an_int = 1; |
| 77 | } |
| 78 | optional string a_string = 1; |
| 79 | required bool a_bool = 2; |
| 80 | optional Nested a_nested_message = 3; |
| 81 | repeated Nested a_repeated_message = 4; |
| 82 | repeated string a_repeated_string = 5; |
| 83 | } |
| 84 | |
| 85 | message HasExtensions { |
| 86 | optional string str1 = 1; |
| 87 | optional string str2 = 2; |
| 88 | optional string str3 = 3; |
| 89 | extensions 10 to max; |
| 90 | } |
| 91 | |
| 92 | message Complex { |
| 93 | message Nested { |
| 94 | required int32 an_int = 2; |
| 95 | } |
| 96 | required string a_string = 1; |
Hao Nguyen | d0f91c8 | 2019-03-06 12:39:12 -0800 | [diff] [blame] | 97 | optional bool an_out_of_order_bool = 9; |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 98 | optional Nested a_nested_message = 4; |
| 99 | repeated Nested a_repeated_message = 5; |
| 100 | repeated string a_repeated_string = 7; |
Hao Nguyen | d0f91c8 | 2019-03-06 12:39:12 -0800 | [diff] [blame] | 101 | optional double a_floating_point_field = 10; |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Josh Haberman | 77af5d0 | 2016-02-04 16:11:07 -0800 | [diff] [blame] | 104 | message OuterMessage { |
| 105 | // Make sure this doesn't conflict with the other Complex message. |
| 106 | message Complex { |
| 107 | optional int32 inner_complex_field = 1; |
| 108 | } |
| 109 | } |
| 110 | |
Yilun Chong | d8c2501 | 2019-02-22 18:13:33 +0800 | [diff] [blame] | 111 | message MineField { |
| 112 | // document.cookie is a banned property in a couple of conformance check |
| 113 | // configs at Google. Verify that having a field called cookie doesn't confuse |
| 114 | // the compiler and break the build. |
| 115 | optional string cookie = 1; |
| 116 | } |
| 117 | |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 118 | message IsExtension { |
| 119 | extend HasExtensions { |
| 120 | optional IsExtension ext_field = 100; |
| 121 | } |
| 122 | optional string ext1 = 1; |
| 123 | |
| 124 | // Extensions of proto2 Descriptor messages will be ignored. |
| 125 | extend google.protobuf.EnumOptions { |
| 126 | optional string simple_option = 42113038; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | message IndirectExtension { |
| 131 | extend HasExtensions { |
| 132 | optional Simple1 simple = 101; |
| 133 | optional string str = 102; |
| 134 | repeated string repeated_str = 103; |
| 135 | repeated Simple1 repeated_simple = 104; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | extend HasExtensions { |
| 140 | optional Simple1 simple1 = 105; |
| 141 | } |
| 142 | |
| 143 | message DefaultValues { |
| 144 | enum Enum { |
| 145 | E1 = 13; |
| 146 | E2 = 77; |
| 147 | } |
Yilun Chong | cb95a7f | 2019-01-11 11:40:52 -0800 | [diff] [blame] | 148 | optional string string_field = 1 [default = "default<>\'\"abc"]; |
| 149 | optional bool bool_field = 2 [default = true]; |
| 150 | optional int64 int_field = 3 [default = 11]; |
| 151 | optional Enum enum_field = 4 [default = E1]; |
| 152 | optional string empty_field = 6 [default = ""]; |
| 153 | optional bytes bytes_field = 8 |
| 154 | [default = "moo"]; // Base64 encoding is "bW9v" |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 155 | } |
| 156 | |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 157 | message FloatingPointFields { |
| 158 | optional float optional_float_field = 1; |
| 159 | required float required_float_field = 2; |
| 160 | repeated float repeated_float_field = 3; |
| 161 | optional float default_float_field = 4 [default = 2.0]; |
| 162 | optional double optional_double_field = 5; |
| 163 | required double required_double_field = 6; |
| 164 | repeated double repeated_double_field = 7; |
| 165 | optional double default_double_field = 8 [default = 2.0]; |
| 166 | } |
| 167 | |
Hao Nguyen | d0f91c8 | 2019-03-06 12:39:12 -0800 | [diff] [blame] | 168 | message BooleanFields { |
| 169 | optional bool optional_boolean_field = 1; |
| 170 | required bool required_boolean_field = 2; |
| 171 | repeated bool repeated_boolean_field = 3; |
| 172 | optional bool default_boolean_field = 4 [default = true]; |
| 173 | } |
| 174 | |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 175 | message TestClone { |
| 176 | optional string str = 1; |
| 177 | optional Simple1 simple1 = 3; |
| 178 | repeated Simple1 simple2 = 5; |
Adam Cozzette | d64a2d9 | 2016-06-29 15:23:27 -0700 | [diff] [blame] | 179 | optional bytes bytes_field = 6; |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 180 | optional string unused = 7; |
| 181 | extensions 10 to max; |
| 182 | } |
| 183 | |
Feng Xiao | 6bbe197 | 2018-08-08 17:00:41 -0700 | [diff] [blame] | 184 | message TestCloneExtension { |
| 185 | extend TestClone { |
| 186 | optional TestCloneExtension low_ext = 11; |
| 187 | } |
| 188 | optional int32 f = 1; |
| 189 | } |
| 190 | |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 191 | message CloneExtension { |
| 192 | extend TestClone { |
| 193 | optional CloneExtension ext_field = 100; |
| 194 | } |
| 195 | optional string ext = 2; |
| 196 | } |
| 197 | |
| 198 | message TestGroup { |
| 199 | repeated group RepeatedGroup = 1 { |
| 200 | required string id = 1; |
| 201 | repeated bool some_bool = 2; |
| 202 | } |
| 203 | required group RequiredGroup = 2 { |
| 204 | required string id = 1; |
| 205 | } |
| 206 | optional group OptionalGroup = 3 { |
| 207 | required string id = 1; |
| 208 | } |
| 209 | optional string id = 4; |
| 210 | required Simple2 required_simple = 5; |
| 211 | optional Simple2 optional_simple = 6; |
| 212 | } |
| 213 | |
| 214 | message TestGroup1 { |
| 215 | optional TestGroup.RepeatedGroup group = 1; |
| 216 | } |
| 217 | |
| 218 | message TestReservedNames { |
| 219 | optional int32 extension = 1; |
| 220 | extensions 10 to max; |
| 221 | } |
| 222 | |
| 223 | message TestReservedNamesExtension { |
| 224 | extend TestReservedNames { |
| 225 | optional int32 foo = 10; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | message TestMessageWithOneof { |
| 230 | |
| 231 | oneof partial_oneof { |
| 232 | string pone = 3; |
| 233 | string pthree = 5; |
| 234 | } |
| 235 | |
| 236 | oneof recursive_oneof { |
| 237 | TestMessageWithOneof rone = 6; |
| 238 | string rtwo = 7; |
| 239 | } |
| 240 | |
| 241 | optional bool normal_field = 8; |
| 242 | repeated string repeated_field = 9; |
| 243 | |
| 244 | oneof default_oneof_a { |
| 245 | int32 aone = 10 [default = 1234]; |
| 246 | int32 atwo = 11; |
| 247 | } |
| 248 | |
| 249 | oneof default_oneof_b { |
| 250 | int32 bone = 12; |
| 251 | int32 btwo = 13 [default = 1234]; |
| 252 | } |
| 253 | } |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 254 | |
Adam Cozzette | c64d86e | 2016-07-06 12:04:49 -0700 | [diff] [blame] | 255 | message TestEndsWithBytes { |
| 256 | optional int32 value = 1; |
| 257 | optional bytes data = 2; |
| 258 | } |
Feng Xiao | 9086d96 | 2016-07-13 13:47:51 -0700 | [diff] [blame] | 259 | |
Adam Cozzette | 0894e07 | 2018-11-09 11:28:22 -0800 | [diff] [blame] | 260 | // This message is for testing extension handling doesn't affect fields before |
| 261 | // pivot. Don't add new field to this message. See b/117298778 for more detail. |
| 262 | message TestLastFieldBeforePivot { |
| 263 | optional int32 last_field_before_pivot = 1; |
| 264 | extensions 100 to max; |
| 265 | } |
| 266 | |
| 267 | extend TestLastFieldBeforePivot { |
| 268 | optional int32 extend_test_last_field_before_pivot_field = 101; |
| 269 | } |
| 270 | |
Adam Cozzette | 5a76e63 | 2016-11-17 16:48:38 -0800 | [diff] [blame] | 271 | |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 272 | message Int64Types { |
Yilun Chong | cb95a7f | 2019-01-11 11:40:52 -0800 | [diff] [blame] | 273 | optional int64 int64_normal = 1 [jstype = JS_NORMAL]; |
| 274 | optional sint64 int64_string = 2 [jstype = JS_STRING]; |
| 275 | optional uint64 int64_number = 3 [jstype = JS_NUMBER]; |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 276 | |
| 277 | } |
| 278 | |
Joshua Haberman | af62fde | 2016-09-20 13:56:18 -0700 | [diff] [blame] | 279 | message TestMapFieldsNoBinary { |
| 280 | map<string, string> map_string_string = 1; |
| 281 | map<string, int32> map_string_int32 = 2; |
| 282 | map<string, int64> map_string_int64 = 3; |
| 283 | map<string, bool> map_string_bool = 4; |
| 284 | map<string, double> map_string_double = 5; |
| 285 | map<string, MapValueEnumNoBinary> map_string_enum = 6; |
| 286 | map<string, MapValueMessageNoBinary> map_string_msg = 7; |
| 287 | |
| 288 | map<int32, string> map_int32_string = 8; |
| 289 | map<int64, string> map_int64_string = 9; |
| 290 | map<bool, string> map_bool_string = 10; |
| 291 | |
| 292 | optional TestMapFieldsNoBinary test_map_fields = 11; |
| 293 | map<string, TestMapFieldsNoBinary> map_string_testmapfields = 12; |
| 294 | } |
| 295 | |
| 296 | enum MapValueEnumNoBinary { |
Adam Cozzette | b4dd686 | 2016-11-18 10:22:46 -0800 | [diff] [blame] | 297 | MAP_VALUE_FOO_NOBINARY = 0; |
| 298 | MAP_VALUE_BAR_NOBINARY = 1; |
| 299 | MAP_VALUE_BAZ_NOBINARY = 2; |
Joshua Haberman | af62fde | 2016-09-20 13:56:18 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | message MapValueMessageNoBinary { |
| 303 | optional int32 foo = 1; |
| 304 | } |
Adam Cozzette | 4a4a162 | 2016-09-27 15:36:41 -0700 | [diff] [blame] | 305 | |
| 306 | message Deeply { |
| 307 | message Nested { |
| 308 | message Message { |
| 309 | optional int32 count = 1; |
| 310 | } |
| 311 | } |
| 312 | } |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 313 | |
Yilun Chong | cb95a7f | 2019-01-11 11:40:52 -0800 | [diff] [blame] | 314 | |
Paul Yang | 7bff839 | 2019-07-19 14:49:01 -0700 | [diff] [blame] | 315 | |
| 316 | enum TestAllowAliasEnum { |
| 317 | option allow_alias = true; |
| 318 | |
| 319 | TEST_ALLOW_ALIAS_DEFAULT = 0; |
| 320 | VALUE1 = 1; |
| 321 | value1 = 1; |
| 322 | } |