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 31// Code generated by protoc-gen-go. DO NOT EDIT. 32// source: google/protobuf/field_mask.proto 33 34// Package fieldmaskpb contains generated types for google/protobuf/field_mask.proto. 35// 36// The FieldMask message represents a set of symbolic field paths. 37// The paths are specific to some target message type, 38// which is not stored within the FieldMask message itself. 39// 40// 41// Constructing a FieldMask 42// 43// The New function is used construct a FieldMask: 44// 45// var messageType *descriptorpb.DescriptorProto 46// fm, err := fieldmaskpb.New(messageType, "field.name", "field.number") 47// if err != nil { 48// ... // handle error 49// } 50// ... // make use of fm 51// 52// The "field.name" and "field.number" paths are valid paths according to the 53// google.protobuf.DescriptorProto message. Use of a path that does not correlate 54// to valid fields reachable from DescriptorProto would result in an error. 55// 56// Once a FieldMask message has been constructed, 57// the Append method can be used to insert additional paths to the path set: 58// 59// var messageType *descriptorpb.DescriptorProto 60// if err := fm.Append(messageType, "options"); err != nil { 61// ... // handle error 62// } 63// 64// 65// Type checking a FieldMask 66// 67// In order to verify that a FieldMask represents a set of fields that are 68// reachable from some target message type, use the IsValid method: 69// 70// var messageType *descriptorpb.DescriptorProto 71// if fm.IsValid(messageType) { 72// ... // make use of fm 73// } 74// 75// IsValid needs to be passed the target message type as an input since the 76// FieldMask message itself does not store the message type that the set of paths 77// are for. 78package fieldmaskpb 79 80import ( 81 proto "google.golang.org/protobuf/proto" 82 protoreflect "google.golang.org/protobuf/reflect/protoreflect" 83 protoimpl "google.golang.org/protobuf/runtime/protoimpl" 84 reflect "reflect" 85 sort "sort" 86 strings "strings" 87 sync "sync" 88) 89 90// `FieldMask` represents a set of symbolic field paths, for example: 91// 92// paths: "f.a" 93// paths: "f.b.d" 94// 95// Here `f` represents a field in some root message, `a` and `b` 96// fields in the message found in `f`, and `d` a field found in the 97// message in `f.b`. 98// 99// Field masks are used to specify a subset of fields that should be 100// returned by a get operation or modified by an update operation. 101// Field masks also have a custom JSON encoding (see below). 102// 103// # Field Masks in Projections 104// 105// When used in the context of a projection, a response message or 106// sub-message is filtered by the API to only contain those fields as 107// specified in the mask. For example, if the mask in the previous 108// example is applied to a response message as follows: 109// 110// f { 111// a : 22 112// b { 113// d : 1 114// x : 2 115// } 116// y : 13 117// } 118// z: 8 119// 120// The result will not contain specific values for fields x,y and z 121// (their value will be set to the default, and omitted in proto text 122// output): 123// 124// 125// f { 126// a : 22 127// b { 128// d : 1 129// } 130// } 131// 132// A repeated field is not allowed except at the last position of a 133// paths string. 134// 135// If a FieldMask object is not present in a get operation, the 136// operation applies to all fields (as if a FieldMask of all fields 137// had been specified). 138// 139// Note that a field mask does not necessarily apply to the 140// top-level response message. In case of a REST get operation, the 141// field mask applies directly to the response, but in case of a REST 142// list operation, the mask instead applies to each individual message 143// in the returned resource list. In case of a REST custom method, 144// other definitions may be used. Where the mask applies will be 145// clearly documented together with its declaration in the API. In 146// any case, the effect on the returned resource/resources is required 147// behavior for APIs. 148// 149// # Field Masks in Update Operations 150// 151// A field mask in update operations specifies which fields of the 152// targeted resource are going to be updated. The API is required 153// to only change the values of the fields as specified in the mask 154// and leave the others untouched. If a resource is passed in to 155// describe the updated values, the API ignores the values of all 156// fields not covered by the mask. 157// 158// If a repeated field is specified for an update operation, new values will 159// be appended to the existing repeated field in the target resource. Note that 160// a repeated field is only allowed in the last position of a `paths` string. 161// 162// If a sub-message is specified in the last position of the field mask for an 163// update operation, then new value will be merged into the existing sub-message 164// in the target resource. 165// 166// For example, given the target message: 167// 168// f { 169// b { 170// d: 1 171// x: 2 172// } 173// c: [1] 174// } 175// 176// And an update message: 177// 178// f { 179// b { 180// d: 10 181// } 182// c: [2] 183// } 184// 185// then if the field mask is: 186// 187// paths: ["f.b", "f.c"] 188// 189// then the result will be: 190// 191// f { 192// b { 193// d: 10 194// x: 2 195// } 196// c: [1, 2] 197// } 198// 199// An implementation may provide options to override this default behavior for 200// repeated and message fields. 201// 202// In order to reset a field's value to the default, the field must 203// be in the mask and set to the default value in the provided resource. 204// Hence, in order to reset all fields of a resource, provide a default 205// instance of the resource and set all fields in the mask, or do 206// not provide a mask as described below. 207// 208// If a field mask is not present on update, the operation applies to 209// all fields (as if a field mask of all fields has been specified). 210// Note that in the presence of schema evolution, this may mean that 211// fields the client does not know and has therefore not filled into 212// the request will be reset to their default. If this is unwanted 213// behavior, a specific service may require a client to always specify 214// a field mask, producing an error if not. 215// 216// As with get operations, the location of the resource which 217// describes the updated values in the request message depends on the 218// operation kind. In any case, the effect of the field mask is 219// required to be honored by the API. 220// 221// ## Considerations for HTTP REST 222// 223// The HTTP kind of an update operation which uses a field mask must 224// be set to PATCH instead of PUT in order to satisfy HTTP semantics 225// (PUT must only be used for full updates). 226// 227// # JSON Encoding of Field Masks 228// 229// In JSON, a field mask is encoded as a single string where paths are 230// separated by a comma. Fields name in each path are converted 231// to/from lower-camel naming conventions. 232// 233// As an example, consider the following message declarations: 234// 235// message Profile { 236// User user = 1; 237// Photo photo = 2; 238// } 239// message User { 240// string display_name = 1; 241// string address = 2; 242// } 243// 244// In proto a field mask for `Profile` may look as such: 245// 246// mask { 247// paths: "user.display_name" 248// paths: "photo" 249// } 250// 251// In JSON, the same mask is represented as below: 252// 253// { 254// mask: "user.displayName,photo" 255// } 256// 257// # Field Masks and Oneof Fields 258// 259// Field masks treat fields in oneofs just as regular fields. Consider the 260// following message: 261// 262// message SampleMessage { 263// oneof test_oneof { 264// string name = 4; 265// SubMessage sub_message = 9; 266// } 267// } 268// 269// The field mask can be: 270// 271// mask { 272// paths: "name" 273// } 274// 275// Or: 276// 277// mask { 278// paths: "sub_message" 279// } 280// 281// Note that oneof type names ("test_oneof" in this case) cannot be used in 282// paths. 283// 284// ## Field Mask Verification 285// 286// The implementation of any API method which has a FieldMask type field in the 287// request should verify the included field paths, and return an 288// `INVALID_ARGUMENT` error if any path is unmappable. 289type FieldMask struct { 290 state protoimpl.MessageState 291 sizeCache protoimpl.SizeCache 292 unknownFields protoimpl.UnknownFields 293 294 // The set of field mask paths. 295 Paths []string `protobuf:"bytes,1,rep,name=paths,proto3" json:"paths,omitempty"` 296} 297 298// New constructs a field mask from a list of paths and verifies that 299// each one is valid according to the specified message type. 300func New(m proto.Message, paths ...string) (*FieldMask, error) { 301 x := new(FieldMask) 302 return x, x.Append(m, paths...) 303} 304 305// Union returns the union of all the paths in the input field masks. 306func Union(mx *FieldMask, my *FieldMask, ms ...*FieldMask) *FieldMask { 307 var out []string 308 out = append(out, mx.GetPaths()...) 309 out = append(out, my.GetPaths()...) 310 for _, m := range ms { 311 out = append(out, m.GetPaths()...) 312 } 313 return &FieldMask{Paths: normalizePaths(out)} 314} 315 316// Intersect returns the intersection of all the paths in the input field masks. 317func Intersect(mx *FieldMask, my *FieldMask, ms ...*FieldMask) *FieldMask { 318 var ss1, ss2 []string // reused buffers for performance 319 intersect := func(out, in []string) []string { 320 ss1 = normalizePaths(append(ss1[:0], in...)) 321 ss2 = normalizePaths(append(ss2[:0], out...)) 322 out = out[:0] 323 for i1, i2 := 0, 0; i1 < len(ss1) && i2 < len(ss2); { 324 switch s1, s2 := ss1[i1], ss2[i2]; { 325 case hasPathPrefix(s1, s2): 326 out = append(out, s1) 327 i1++ 328 case hasPathPrefix(s2, s1): 329 out = append(out, s2) 330 i2++ 331 case lessPath(s1, s2): 332 i1++ 333 case lessPath(s2, s1): 334 i2++ 335 } 336 } 337 return out 338 } 339 340 out := Union(mx, my, ms...).GetPaths() 341 out = intersect(out, mx.GetPaths()) 342 out = intersect(out, my.GetPaths()) 343 for _, m := range ms { 344 out = intersect(out, m.GetPaths()) 345 } 346 return &FieldMask{Paths: normalizePaths(out)} 347} 348 349// IsValid reports whether all the paths are syntactically valid and 350// refer to known fields in the specified message type. 351// It reports false for a nil FieldMask. 352func (x *FieldMask) IsValid(m proto.Message) bool { 353 paths := x.GetPaths() 354 return x != nil && numValidPaths(m, paths) == len(paths) 355} 356 357// Append appends a list of paths to the mask and verifies that each one 358// is valid according to the specified message type. 359// An invalid path is not appended and breaks insertion of subsequent paths. 360func (x *FieldMask) Append(m proto.Message, paths ...string) error { 361 numValid := numValidPaths(m, paths) 362 x.Paths = append(x.Paths, paths[:numValid]...) 363 paths = paths[numValid:] 364 if len(paths) > 0 { 365 name := m.ProtoReflect().Descriptor().FullName() 366 return protoimpl.X.NewError("invalid path %q for message %q", paths[0], name) 367 } 368 return nil 369} 370 371func numValidPaths(m proto.Message, paths []string) int { 372 md0 := m.ProtoReflect().Descriptor() 373 for i, path := range paths { 374 md := md0 375 if !rangeFields(path, func(field string) bool { 376 // Search the field within the message. 377 if md == nil { 378 return false // not within a message 379 } 380 fd := md.Fields().ByName(protoreflect.Name(field)) 381 // The real field name of a group is the message name. 382 if fd == nil { 383 gd := md.Fields().ByName(protoreflect.Name(strings.ToLower(field))) 384 if gd != nil && gd.Kind() == protoreflect.GroupKind && string(gd.Message().Name()) == field { 385 fd = gd 386 } 387 } else if fd.Kind() == protoreflect.GroupKind && string(fd.Message().Name()) != field { 388 fd = nil 389 } 390 if fd == nil { 391 return false // message has does not have this field 392 } 393 394 // Identify the next message to search within. 395 md = fd.Message() // may be nil 396 397 // Repeated fields are only allowed at the last postion. 398 if fd.IsList() || fd.IsMap() { 399 md = nil 400 } 401 402 return true 403 }) { 404 return i 405 } 406 } 407 return len(paths) 408} 409 410// Normalize converts the mask to its canonical form where all paths are sorted 411// and redundant paths are removed. 412func (x *FieldMask) Normalize() { 413 x.Paths = normalizePaths(x.Paths) 414} 415 416func normalizePaths(paths []string) []string { 417 sort.Slice(paths, func(i, j int) bool { 418 return lessPath(paths[i], paths[j]) 419 }) 420 421 // Elide any path that is a prefix match on the previous. 422 out := paths[:0] 423 for _, path := range paths { 424 if len(out) > 0 && hasPathPrefix(path, out[len(out)-1]) { 425 continue 426 } 427 out = append(out, path) 428 } 429 return out 430} 431 432// hasPathPrefix is like strings.HasPrefix, but further checks for either 433// an exact matche or that the prefix is delimited by a dot. 434func hasPathPrefix(path, prefix string) bool { 435 return strings.HasPrefix(path, prefix) && (len(path) == len(prefix) || path[len(prefix)] == '.') 436} 437 438// lessPath is a lexicographical comparison where dot is specially treated 439// as the smallest symbol. 440func lessPath(x, y string) bool { 441 for i := 0; i < len(x) && i < len(y); i++ { 442 if x[i] != y[i] { 443 return (x[i] - '.') < (y[i] - '.') 444 } 445 } 446 return len(x) < len(y) 447} 448 449// rangeFields is like strings.Split(path, "."), but avoids allocations by 450// iterating over each field in place and calling a iterator function. 451func rangeFields(path string, f func(field string) bool) bool { 452 for { 453 var field string 454 if i := strings.IndexByte(path, '.'); i >= 0 { 455 field, path = path[:i], path[i:] 456 } else { 457 field, path = path, "" 458 } 459 460 if !f(field) { 461 return false 462 } 463 464 if len(path) == 0 { 465 return true 466 } 467 path = strings.TrimPrefix(path, ".") 468 } 469} 470 471func (x *FieldMask) Reset() { 472 *x = FieldMask{} 473 if protoimpl.UnsafeEnabled { 474 mi := &file_google_protobuf_field_mask_proto_msgTypes[0] 475 ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 476 ms.StoreMessageInfo(mi) 477 } 478} 479 480func (x *FieldMask) String() string { 481 return protoimpl.X.MessageStringOf(x) 482} 483 484func (*FieldMask) ProtoMessage() {} 485 486func (x *FieldMask) ProtoReflect() protoreflect.Message { 487 mi := &file_google_protobuf_field_mask_proto_msgTypes[0] 488 if protoimpl.UnsafeEnabled && x != nil { 489 ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 490 if ms.LoadMessageInfo() == nil { 491 ms.StoreMessageInfo(mi) 492 } 493 return ms 494 } 495 return mi.MessageOf(x) 496} 497 498// Deprecated: Use FieldMask.ProtoReflect.Descriptor instead. 499func (*FieldMask) Descriptor() ([]byte, []int) { 500 return file_google_protobuf_field_mask_proto_rawDescGZIP(), []int{0} 501} 502 503func (x *FieldMask) GetPaths() []string { 504 if x != nil { 505 return x.Paths 506 } 507 return nil 508} 509 510var File_google_protobuf_field_mask_proto protoreflect.FileDescriptor 511 512var file_google_protobuf_field_mask_proto_rawDesc = []byte{ 513 0x0a, 0x20, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 514 0x66, 0x2f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x5f, 0x6d, 0x61, 0x73, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 515 0x74, 0x6f, 0x12, 0x0f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 516 0x62, 0x75, 0x66, 0x22, 0x21, 0x0a, 0x09, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x4d, 0x61, 0x73, 0x6b, 517 0x12, 0x14, 0x0a, 0x05, 0x70, 0x61, 0x74, 0x68, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 518 0x05, 0x70, 0x61, 0x74, 0x68, 0x73, 0x42, 0x85, 0x01, 0x0a, 0x13, 0x63, 0x6f, 0x6d, 0x2e, 0x67, 519 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x42, 0x0e, 520 0x46, 0x69, 0x65, 0x6c, 0x64, 0x4d, 0x61, 0x73, 0x6b, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 521 0x5a, 0x32, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2e, 522 0x6f, 0x72, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x79, 0x70, 523 0x65, 0x73, 0x2f, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x2f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x6d, 0x61, 524 0x73, 0x6b, 0x70, 0x62, 0xf8, 0x01, 0x01, 0xa2, 0x02, 0x03, 0x47, 0x50, 0x42, 0xaa, 0x02, 0x1e, 525 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 526 0x57, 0x65, 0x6c, 0x6c, 0x4b, 0x6e, 0x6f, 0x77, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x62, 0x06, 527 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 528} 529 530var ( 531 file_google_protobuf_field_mask_proto_rawDescOnce sync.Once 532 file_google_protobuf_field_mask_proto_rawDescData = file_google_protobuf_field_mask_proto_rawDesc 533) 534 535func file_google_protobuf_field_mask_proto_rawDescGZIP() []byte { 536 file_google_protobuf_field_mask_proto_rawDescOnce.Do(func() { 537 file_google_protobuf_field_mask_proto_rawDescData = protoimpl.X.CompressGZIP(file_google_protobuf_field_mask_proto_rawDescData) 538 }) 539 return file_google_protobuf_field_mask_proto_rawDescData 540} 541 542var file_google_protobuf_field_mask_proto_msgTypes = make([]protoimpl.MessageInfo, 1) 543var file_google_protobuf_field_mask_proto_goTypes = []interface{}{ 544 (*FieldMask)(nil), // 0: google.protobuf.FieldMask 545} 546var file_google_protobuf_field_mask_proto_depIdxs = []int32{ 547 0, // [0:0] is the sub-list for method output_type 548 0, // [0:0] is the sub-list for method input_type 549 0, // [0:0] is the sub-list for extension type_name 550 0, // [0:0] is the sub-list for extension extendee 551 0, // [0:0] is the sub-list for field type_name 552} 553 554func init() { file_google_protobuf_field_mask_proto_init() } 555func file_google_protobuf_field_mask_proto_init() { 556 if File_google_protobuf_field_mask_proto != nil { 557 return 558 } 559 if !protoimpl.UnsafeEnabled { 560 file_google_protobuf_field_mask_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 561 switch v := v.(*FieldMask); i { 562 case 0: 563 return &v.state 564 case 1: 565 return &v.sizeCache 566 case 2: 567 return &v.unknownFields 568 default: 569 return nil 570 } 571 } 572 } 573 type x struct{} 574 out := protoimpl.TypeBuilder{ 575 File: protoimpl.DescBuilder{ 576 GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 577 RawDescriptor: file_google_protobuf_field_mask_proto_rawDesc, 578 NumEnums: 0, 579 NumMessages: 1, 580 NumExtensions: 0, 581 NumServices: 0, 582 }, 583 GoTypes: file_google_protobuf_field_mask_proto_goTypes, 584 DependencyIndexes: file_google_protobuf_field_mask_proto_depIdxs, 585 MessageInfos: file_google_protobuf_field_mask_proto_msgTypes, 586 }.Build() 587 File_google_protobuf_field_mask_proto = out.File 588 file_google_protobuf_field_mask_proto_rawDesc = nil 589 file_google_protobuf_field_mask_proto_goTypes = nil 590 file_google_protobuf_field_mask_proto_depIdxs = nil 591} 592