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