github.com/jhump/protoreflect@v1.16.0/internal/testprotos/desc_test_complex.proto (about) 1 syntax = "proto2"; 2 3 package foo.bar; 4 5 option go_package = "github.com/jhump/protoreflect/internal/testprotos"; 6 7 import "google/protobuf/descriptor.proto"; 8 9 message Simple { 10 optional string name = 1; 11 optional uint64 id = 2; 12 optional bytes _extra = 3; // default JSON name will be capitalized 13 repeated bool _ = 4; // default JSON name will be empty(!) 14 } 15 16 extend . google. // identifier broken up strangely should still be accepted 17 protobuf . 18 ExtensionRangeOptions { 19 optional string label = 20000; 20 } 21 22 message Test { 23 optional string foo = 1 [json_name = "|foo|"]; 24 repeated int32 array = 2; 25 optional Simple s = 3; 26 repeated Simple r = 4; 27 map<string, int32> m = 5; 28 29 optional bytes b = 6 [default = "\0\1\2\3\4\5\6\7fubar!"]; 30 31 extensions 100 to 200; 32 33 extensions 249, 300 to 350, 500 to 550, 20000 to max [(label) = "jazz \"hands\""]; 34 35 message Nested { 36 extend google.protobuf.MessageOptions { 37 optional int32 fooblez = 20003; 38 } 39 message _NestedNested { 40 enum EEE { 41 OK = 0; 42 V1 = 1; 43 V2 = 2; 44 V3 = 3; 45 V4 = 4; 46 V5 = 5; 47 V6 = 6; 48 } 49 option (fooblez) = 10101; 50 extend Test { 51 optional string _garblez = 100; 52 } 53 option (rept) = { foo: "goo" [foo.bar.Test.Nested._NestedNested._garblez]: "boo" }; 54 message NestedNestedNested { 55 option (rept) = { foo: "hoo" [Test.Nested._NestedNested._garblez]: "spoo" }; 56 57 optional Test Test = 1; 58 } 59 } 60 } 61 } 62 63 enum EnumWithReservations { 64 X = 2; 65 Y = 3; 66 Z = 4; 67 reserved 1000 to max; 68 reserved -2 to 1; 69 reserved 5 to 10, 12 to 15, 18; 70 reserved -5 to -3; 71 reserved "C", "B", "A"; 72 } 73 74 message MessageWithReservations { 75 reserved 5 to 10, 12 to 15, 18; 76 reserved 1000 to max; 77 reserved "A", "B", "C"; 78 } 79 80 message MessageWithMap { 81 map<string, Simple> vals = 1; 82 } 83 84 extend google.protobuf.MessageOptions { 85 repeated Test rept = 20002; 86 optional Test.Nested._NestedNested.EEE eee = 20010; 87 optional Another a = 20020; 88 optional MessageWithMap map_vals = 20030; 89 } 90 91 message Another { 92 option (.foo.bar.rept) = { foo: "abc" s < name: "foo", id: 123 >, array: [1, 2 ,3], r:[<name:"f">, {name:"s"}, {id:456} ], }; 93 option (foo.bar.rept) = { foo: "def" s { name: "bar", id: 321 }, array: [3, 2 ,1], r:{name:"g"} r:{name:"s"}}; 94 option (rept) = { foo: "def" }; 95 option (eee) = V1; 96 option (a) = { fff: OK }; 97 option (a).test = { m { key: "foo" value: 100 } m { key: "bar" value: 200 }}; 98 option (a).test.foo = "m&m"; 99 option (a).test.s.name = "yolo"; 100 option (a).test.s.id = 98765; 101 option (a).test.array = 1; 102 option (a).test.array = 2; 103 option (a).test.(.foo.bar.Test.Nested._NestedNested._garblez) = "whoah!"; 104 105 option (map_vals).vals = {}; // no key, no value 106 option (map_vals).vals = {key: "foo"}; // no value 107 option (map_vals).vals = {key: "bar", value: {name: "baz"}}; 108 109 optional Test test = 1; 110 optional Test.Nested._NestedNested.EEE fff = 2 [default = V1]; 111 } 112 113 message Validator { 114 optional bool authenticated = 1; 115 116 enum Action { 117 LOGIN = 0; 118 READ = 1; 119 WRITE = 2; 120 } 121 message Permission { 122 optional Action action = 1; 123 optional string entity = 2; 124 } 125 126 repeated Permission permission = 2; 127 } 128 129 extend google.protobuf.MethodOptions { 130 optional Validator validator = 12345; 131 } 132 133 service TestTestService { 134 rpc UserAuth(Test) returns (Test) { 135 option (validator) = { 136 authenticated: true 137 permission: { 138 action: LOGIN 139 entity: "client" 140 } 141 }; 142 } 143 rpc Get(Test) returns (Test) { 144 option (validator) = { 145 authenticated: true 146 permission: { 147 action: READ 148 entity: "user" 149 } 150 }; 151 } 152 } 153 154 message Rule { 155 message StringRule { 156 optional string pattern = 1; 157 optional bool allow_empty = 2; 158 optional int32 min_len = 3; 159 optional int32 max_len = 4; 160 } 161 message IntRule { 162 optional int64 min_val = 1; 163 optional uint64 max_val = 2; 164 } 165 message RepeatedRule { 166 optional bool allow_empty = 1; 167 optional int32 min_items = 2; 168 optional int32 max_items = 3; 169 optional Rule items = 4; 170 } 171 oneof rule { 172 StringRule string = 1; 173 RepeatedRule repeated = 2; 174 IntRule int = 3; 175 group FloatRule = 4 { 176 optional double min_val = 1; 177 optional double max_val = 2; 178 } 179 } 180 } 181 182 extend google.protobuf.FieldOptions { 183 optional Rule rules = 1234; 184 } 185 186 message IsAuthorizedReq { 187 repeated string subjects = 1 188 [(rules).repeated = { 189 min_items: 1, 190 items: { string: { pattern: "^(?:(?:team:(?:local|ldap))|user):[[:alnum:]_-]+$" } }, 191 }]; 192 } 193 194 // tests cases where field names collide with keywords 195 196 message KeywordCollisions { 197 optional bool syntax = 1; 198 optional bool import = 2; 199 optional bool public = 3; 200 optional bool weak = 4; 201 optional bool package = 5; 202 optional string string = 6; 203 optional bytes bytes = 7; 204 optional int32 int32 = 8; 205 optional int64 int64 = 9; 206 optional uint32 uint32 = 10; 207 optional uint64 uint64 = 11; 208 optional sint32 sint32 = 12; 209 optional sint64 sint64 = 13; 210 optional fixed32 fixed32 = 14; 211 optional fixed64 fixed64 = 15; 212 optional sfixed32 sfixed32 = 16; 213 optional sfixed64 sfixed64 = 17; 214 optional bool bool = 18; 215 optional float float = 19; 216 optional double double = 20; 217 optional bool optional = 21; 218 optional bool repeated = 22; 219 optional bool required = 23; 220 optional bool message = 24; 221 optional bool enum = 25; 222 optional bool service = 26; 223 optional bool rpc = 27; 224 optional bool option = 28; 225 optional bool extend = 29; 226 optional bool extensions = 30; 227 optional bool reserved = 31; 228 optional bool to = 32; 229 optional int32 true = 33; 230 optional int32 false = 34; 231 optional int32 default = 35; 232 } 233 234 extend google.protobuf.FieldOptions { 235 optional bool syntax = 20001; 236 optional bool import = 20002; 237 optional bool public = 20003; 238 optional bool weak = 20004; 239 optional bool package = 20005; 240 optional string string = 20006; 241 optional bytes bytes = 20007; 242 optional int32 int32 = 20008; 243 optional int64 int64 = 20009; 244 optional uint32 uint32 = 20010; 245 optional uint64 uint64 = 20011; 246 optional sint32 sint32 = 20012; 247 optional sint64 sint64 = 20013; 248 optional fixed32 fixed32 = 20014; 249 optional fixed64 fixed64 = 20015; 250 optional sfixed32 sfixed32 = 20016; 251 optional sfixed64 sfixed64 = 20017; 252 optional bool bool = 20018; 253 optional float float = 20019; 254 optional double double = 20020; 255 optional bool optional = 20021; 256 optional bool repeated = 20022; 257 optional bool required = 20023; 258 optional bool message = 20024; 259 optional bool enum = 20025; 260 optional bool service = 20026; 261 optional bool rpc = 20027; 262 optional bool option = 20028; 263 optional bool extend = 20029; 264 optional bool extensions = 20030; 265 optional bool reserved = 20031; 266 optional bool to = 20032; 267 optional int32 true = 20033; 268 optional int32 false = 20034; 269 optional int32 default = 20035; 270 optional KeywordCollisions boom = 20036; 271 } 272 273 message KeywordCollisionOptions { 274 optional uint64 id = 1 [ 275 (syntax) = true, (import) = true, (public) = true, (weak) = true, (package) = true, 276 (string) = "string\u8765\U00107f6d\a\b\f\n\r\t\v\\\"\'\?\x42", (bytes) = "bytes\u8765\U00107f6d\a\b\f\n\r\t\v\\\"\'\?\x42", (bool) = true, 277 (float) = 3.14, (double) = 3.14159, 278 (int32) = 32, (int64) = 64, (uint32) = 3200, (uint64) = 6400, (sint32) = -32, (sint64) = -64, 279 (fixed32) = 3232, (fixed64) = 6464, (sfixed32) = -3232, (sfixed64) = -6464, 280 (optional) = true, (repeated) = true, (required) = true, 281 (message) = true, (enum) = true, (service) = true, (rpc) = true, 282 (option) = true, (extend) = true, (extensions) = true, (reserved) = true, 283 (to) = true, (true) = 111, (false) = -111, (default) = 222 284 ]; 285 optional string name = 2 [ 286 (boom) = { 287 syntax: true, import: true, public: true, weak: true, package: true, 288 string: "string", bytes: "bytes", bool: true, 289 float: 3.14, double: 3.14159, 290 int32: 32, int64: 64, uint32: 3200, uint64: 6400, sint32: -32, sint64: -64, 291 fixed32: 3232, fixed64: 6464, sfixed32: -3232, sfixed64: -6464, 292 optional: true, repeated: true, required: true, 293 message: true, enum: true, service: true, rpc: true, 294 option: true, extend: true, extensions: true, reserved: true, 295 to: true, true: 111, false: -111, default: 222 296 } 297 ]; 298 } 299 // comment for last element in file, KeywordCollisionOptions