github.com/cloudwan/edgelq-sdk@v1.15.4/monitoring/resources/v4/alert/alert.pb.fieldmask.go (about) 1 // Code generated by protoc-gen-goten-object 2 // File: edgelq/monitoring/proto/v4/alert.proto 3 // DO NOT EDIT!!! 4 5 package alert 6 7 import ( 8 "encoding/json" 9 "strings" 10 11 "google.golang.org/grpc/codes" 12 "google.golang.org/grpc/status" 13 "google.golang.org/protobuf/proto" 14 preflect "google.golang.org/protobuf/reflect/protoreflect" 15 googlefieldmaskpb "google.golang.org/protobuf/types/known/fieldmaskpb" 16 17 gotenobject "github.com/cloudwan/goten-sdk/runtime/object" 18 ) 19 20 // proto imports 21 import ( 22 alerting_condition "github.com/cloudwan/edgelq-sdk/monitoring/resources/v4/alerting_condition" 23 common "github.com/cloudwan/edgelq-sdk/monitoring/resources/v4/common" 24 meta "github.com/cloudwan/goten-sdk/types/meta" 25 ) 26 27 // ensure the imports are used 28 var ( 29 _ = new(json.Marshaler) 30 _ = strings.Builder{} 31 32 _ = codes.NotFound 33 _ = status.Status{} 34 _ = new(proto.Message) 35 _ = new(preflect.Message) 36 _ = googlefieldmaskpb.FieldMask{} 37 38 _ = new(gotenobject.FieldMask) 39 ) 40 41 // make sure we're using proto imports 42 var ( 43 _ = &alerting_condition.AlertingCondition{} 44 _ = &common.LabelDescriptor{} 45 _ = &meta.Meta{} 46 ) 47 48 type Alert_FieldMask struct { 49 Paths []Alert_FieldPath 50 } 51 52 func FullAlert_FieldMask() *Alert_FieldMask { 53 res := &Alert_FieldMask{} 54 res.Paths = append(res.Paths, &Alert_FieldTerminalPath{selector: Alert_FieldPathSelectorName}) 55 res.Paths = append(res.Paths, &Alert_FieldTerminalPath{selector: Alert_FieldPathSelectorMetadata}) 56 res.Paths = append(res.Paths, &Alert_FieldTerminalPath{selector: Alert_FieldPathSelectorDisplayName}) 57 res.Paths = append(res.Paths, &Alert_FieldTerminalPath{selector: Alert_FieldPathSelectorInfo}) 58 res.Paths = append(res.Paths, &Alert_FieldTerminalPath{selector: Alert_FieldPathSelectorState}) 59 return res 60 } 61 62 func (fieldMask *Alert_FieldMask) String() string { 63 if fieldMask == nil { 64 return "<nil>" 65 } 66 pathsStr := make([]string, 0, len(fieldMask.Paths)) 67 for _, path := range fieldMask.Paths { 68 pathsStr = append(pathsStr, path.String()) 69 } 70 return strings.Join(pathsStr, ", ") 71 } 72 73 func (fieldMask *Alert_FieldMask) IsFull() bool { 74 if fieldMask == nil { 75 return false 76 } 77 presentSelectors := make([]bool, 5) 78 for _, path := range fieldMask.Paths { 79 if asFinal, ok := path.(*Alert_FieldTerminalPath); ok { 80 presentSelectors[int(asFinal.selector)] = true 81 } 82 } 83 for _, flag := range presentSelectors { 84 if !flag { 85 return false 86 } 87 } 88 return true 89 } 90 91 func (fieldMask *Alert_FieldMask) ProtoReflect() preflect.Message { 92 return gotenobject.MakeFieldMaskReflection(fieldMask, func(raw string) (gotenobject.FieldPath, error) { 93 return ParseAlert_FieldPath(raw) 94 }) 95 } 96 97 func (fieldMask *Alert_FieldMask) ProtoMessage() {} 98 99 func (fieldMask *Alert_FieldMask) Reset() { 100 if fieldMask != nil { 101 fieldMask.Paths = nil 102 } 103 } 104 105 func (fieldMask *Alert_FieldMask) Subtract(other *Alert_FieldMask) *Alert_FieldMask { 106 result := &Alert_FieldMask{} 107 removedSelectors := make([]bool, 5) 108 otherSubMasks := map[Alert_FieldPathSelector]gotenobject.FieldMask{ 109 Alert_FieldPathSelectorMetadata: &meta.Meta_FieldMask{}, 110 Alert_FieldPathSelectorInfo: &Alert_Info_FieldMask{}, 111 Alert_FieldPathSelectorState: &Alert_State_FieldMask{}, 112 } 113 mySubMasks := map[Alert_FieldPathSelector]gotenobject.FieldMask{ 114 Alert_FieldPathSelectorMetadata: &meta.Meta_FieldMask{}, 115 Alert_FieldPathSelectorInfo: &Alert_Info_FieldMask{}, 116 Alert_FieldPathSelectorState: &Alert_State_FieldMask{}, 117 } 118 119 for _, path := range other.GetPaths() { 120 switch tp := path.(type) { 121 case *Alert_FieldTerminalPath: 122 removedSelectors[int(tp.selector)] = true 123 case *Alert_FieldSubPath: 124 otherSubMasks[tp.selector].AppendRawPath(tp.subPath) 125 } 126 } 127 for _, path := range fieldMask.GetPaths() { 128 if !removedSelectors[int(path.Selector())] { 129 if otherSubMask := otherSubMasks[path.Selector()]; otherSubMask != nil && otherSubMask.PathsCount() > 0 { 130 if tp, ok := path.(*Alert_FieldTerminalPath); ok { 131 switch tp.selector { 132 case Alert_FieldPathSelectorMetadata: 133 mySubMasks[Alert_FieldPathSelectorMetadata] = meta.FullMeta_FieldMask() 134 case Alert_FieldPathSelectorInfo: 135 mySubMasks[Alert_FieldPathSelectorInfo] = FullAlert_Info_FieldMask() 136 case Alert_FieldPathSelectorState: 137 mySubMasks[Alert_FieldPathSelectorState] = FullAlert_State_FieldMask() 138 } 139 } else if tp, ok := path.(*Alert_FieldSubPath); ok { 140 mySubMasks[tp.selector].AppendRawPath(tp.subPath) 141 } 142 } else { 143 result.Paths = append(result.Paths, path) 144 } 145 } 146 } 147 for selector, mySubMask := range mySubMasks { 148 if mySubMask.PathsCount() > 0 { 149 for _, allowedPath := range mySubMask.SubtractRaw(otherSubMasks[selector]).GetRawPaths() { 150 result.Paths = append(result.Paths, &Alert_FieldSubPath{selector: selector, subPath: allowedPath}) 151 } 152 } 153 } 154 155 if len(result.Paths) == 0 { 156 return nil 157 } 158 return result 159 } 160 161 func (fieldMask *Alert_FieldMask) SubtractRaw(other gotenobject.FieldMask) gotenobject.FieldMask { 162 return fieldMask.Subtract(other.(*Alert_FieldMask)) 163 } 164 165 // FilterInputFields generates copy of field paths with output_only field paths removed 166 func (fieldMask *Alert_FieldMask) FilterInputFields() *Alert_FieldMask { 167 result := &Alert_FieldMask{} 168 for _, path := range fieldMask.Paths { 169 switch path.Selector() { 170 case Alert_FieldPathSelectorDisplayName: 171 case Alert_FieldPathSelectorMetadata: 172 if _, ok := path.(*Alert_FieldTerminalPath); ok { 173 for _, subpath := range meta.FullMeta_FieldMask().FilterInputFields().Paths { 174 result.Paths = append(result.Paths, &Alert_FieldSubPath{selector: path.Selector(), subPath: subpath}) 175 } 176 } else if sub, ok := path.(*Alert_FieldSubPath); ok { 177 selectedMask := &meta.Meta_FieldMask{ 178 Paths: []meta.Meta_FieldPath{sub.subPath.(meta.Meta_FieldPath)}, 179 } 180 for _, allowedPath := range selectedMask.FilterInputFields().Paths { 181 result.Paths = append(result.Paths, &Alert_FieldSubPath{selector: Alert_FieldPathSelectorMetadata, subPath: allowedPath}) 182 } 183 } 184 case Alert_FieldPathSelectorInfo: 185 if _, ok := path.(*Alert_FieldTerminalPath); ok { 186 for _, subpath := range FullAlert_Info_FieldMask().FilterInputFields().Paths { 187 result.Paths = append(result.Paths, &Alert_FieldSubPath{selector: path.Selector(), subPath: subpath}) 188 } 189 } else if sub, ok := path.(*Alert_FieldSubPath); ok { 190 selectedMask := &Alert_Info_FieldMask{ 191 Paths: []AlertInfo_FieldPath{sub.subPath.(AlertInfo_FieldPath)}, 192 } 193 for _, allowedPath := range selectedMask.FilterInputFields().Paths { 194 result.Paths = append(result.Paths, &Alert_FieldSubPath{selector: Alert_FieldPathSelectorInfo, subPath: allowedPath}) 195 } 196 } 197 default: 198 result.Paths = append(result.Paths, path) 199 } 200 } 201 return result 202 } 203 204 // ToFieldMask is used for proto conversions 205 func (fieldMask *Alert_FieldMask) ToProtoFieldMask() *googlefieldmaskpb.FieldMask { 206 protoFieldMask := &googlefieldmaskpb.FieldMask{} 207 for _, path := range fieldMask.Paths { 208 protoFieldMask.Paths = append(protoFieldMask.Paths, path.String()) 209 } 210 return protoFieldMask 211 } 212 213 func (fieldMask *Alert_FieldMask) FromProtoFieldMask(protoFieldMask *googlefieldmaskpb.FieldMask) error { 214 if fieldMask == nil { 215 return status.Error(codes.Internal, "target field mask is nil") 216 } 217 fieldMask.Paths = make([]Alert_FieldPath, 0, len(protoFieldMask.Paths)) 218 for _, strPath := range protoFieldMask.Paths { 219 path, err := ParseAlert_FieldPath(strPath) 220 if err != nil { 221 return err 222 } 223 fieldMask.Paths = append(fieldMask.Paths, path) 224 } 225 return nil 226 } 227 228 // implement methods required by customType 229 func (fieldMask Alert_FieldMask) Marshal() ([]byte, error) { 230 protoFieldMask := fieldMask.ToProtoFieldMask() 231 return proto.Marshal(protoFieldMask) 232 } 233 234 func (fieldMask *Alert_FieldMask) Unmarshal(data []byte) error { 235 protoFieldMask := &googlefieldmaskpb.FieldMask{} 236 if err := proto.Unmarshal(data, protoFieldMask); err != nil { 237 return err 238 } 239 if err := fieldMask.FromProtoFieldMask(protoFieldMask); err != nil { 240 return err 241 } 242 return nil 243 } 244 245 func (fieldMask *Alert_FieldMask) Size() int { 246 return proto.Size(fieldMask.ToProtoFieldMask()) 247 } 248 249 func (fieldMask Alert_FieldMask) MarshalJSON() ([]byte, error) { 250 return json.Marshal(fieldMask.ToProtoFieldMask()) 251 } 252 253 func (fieldMask *Alert_FieldMask) UnmarshalJSON(data []byte) error { 254 protoFieldMask := &googlefieldmaskpb.FieldMask{} 255 if err := json.Unmarshal(data, protoFieldMask); err != nil { 256 return err 257 } 258 if err := fieldMask.FromProtoFieldMask(protoFieldMask); err != nil { 259 return err 260 } 261 return nil 262 } 263 264 func (fieldMask *Alert_FieldMask) AppendPath(path Alert_FieldPath) { 265 fieldMask.Paths = append(fieldMask.Paths, path) 266 } 267 268 func (fieldMask *Alert_FieldMask) AppendRawPath(path gotenobject.FieldPath) { 269 fieldMask.Paths = append(fieldMask.Paths, path.(Alert_FieldPath)) 270 } 271 272 func (fieldMask *Alert_FieldMask) GetPaths() []Alert_FieldPath { 273 if fieldMask == nil { 274 return nil 275 } 276 return fieldMask.Paths 277 } 278 279 func (fieldMask *Alert_FieldMask) GetRawPaths() []gotenobject.FieldPath { 280 if fieldMask == nil { 281 return nil 282 } 283 rawPaths := make([]gotenobject.FieldPath, 0, len(fieldMask.Paths)) 284 for _, path := range fieldMask.Paths { 285 rawPaths = append(rawPaths, path) 286 } 287 return rawPaths 288 } 289 290 func (fieldMask *Alert_FieldMask) SetFromCliFlag(raw string) error { 291 path, err := ParseAlert_FieldPath(raw) 292 if err != nil { 293 return err 294 } 295 fieldMask.Paths = append(fieldMask.Paths, path) 296 return nil 297 } 298 299 func (fieldMask *Alert_FieldMask) Set(target, source *Alert) { 300 for _, path := range fieldMask.Paths { 301 val, _ := path.GetSingle(source) 302 // if val is nil, then field does not exist in source, skip 303 // otherwise, process (can still reflect.ValueOf(val).IsNil!) 304 if val != nil { 305 path.WithIValue(val).SetTo(&target) 306 } 307 } 308 } 309 310 func (fieldMask *Alert_FieldMask) SetRaw(target, source gotenobject.GotenObjectExt) { 311 fieldMask.Set(target.(*Alert), source.(*Alert)) 312 } 313 314 func (fieldMask *Alert_FieldMask) Project(source *Alert) *Alert { 315 if source == nil { 316 return nil 317 } 318 if fieldMask == nil { 319 return source 320 } 321 result := &Alert{} 322 metadataMask := &meta.Meta_FieldMask{} 323 wholeMetadataAccepted := false 324 infoMask := &Alert_Info_FieldMask{} 325 wholeInfoAccepted := false 326 stateMask := &Alert_State_FieldMask{} 327 wholeStateAccepted := false 328 329 for _, p := range fieldMask.Paths { 330 switch tp := p.(type) { 331 case *Alert_FieldTerminalPath: 332 switch tp.selector { 333 case Alert_FieldPathSelectorName: 334 result.Name = source.Name 335 case Alert_FieldPathSelectorMetadata: 336 result.Metadata = source.Metadata 337 wholeMetadataAccepted = true 338 case Alert_FieldPathSelectorDisplayName: 339 result.DisplayName = source.DisplayName 340 case Alert_FieldPathSelectorInfo: 341 result.Info = source.Info 342 wholeInfoAccepted = true 343 case Alert_FieldPathSelectorState: 344 result.State = source.State 345 wholeStateAccepted = true 346 } 347 case *Alert_FieldSubPath: 348 switch tp.selector { 349 case Alert_FieldPathSelectorMetadata: 350 metadataMask.AppendPath(tp.subPath.(meta.Meta_FieldPath)) 351 case Alert_FieldPathSelectorInfo: 352 infoMask.AppendPath(tp.subPath.(AlertInfo_FieldPath)) 353 case Alert_FieldPathSelectorState: 354 stateMask.AppendPath(tp.subPath.(AlertState_FieldPath)) 355 } 356 } 357 } 358 if wholeMetadataAccepted == false && len(metadataMask.Paths) > 0 { 359 result.Metadata = metadataMask.Project(source.GetMetadata()) 360 } 361 if wholeInfoAccepted == false && len(infoMask.Paths) > 0 { 362 result.Info = infoMask.Project(source.GetInfo()) 363 } 364 if wholeStateAccepted == false && len(stateMask.Paths) > 0 { 365 result.State = stateMask.Project(source.GetState()) 366 } 367 return result 368 } 369 370 func (fieldMask *Alert_FieldMask) ProjectRaw(source gotenobject.GotenObjectExt) gotenobject.GotenObjectExt { 371 return fieldMask.Project(source.(*Alert)) 372 } 373 374 func (fieldMask *Alert_FieldMask) PathsCount() int { 375 if fieldMask == nil { 376 return 0 377 } 378 return len(fieldMask.Paths) 379 } 380 381 type Alert_Info_FieldMask struct { 382 Paths []AlertInfo_FieldPath 383 } 384 385 func FullAlert_Info_FieldMask() *Alert_Info_FieldMask { 386 res := &Alert_Info_FieldMask{} 387 res.Paths = append(res.Paths, &AlertInfo_FieldTerminalPath{selector: AlertInfo_FieldPathSelectorTimeSerie}) 388 res.Paths = append(res.Paths, &AlertInfo_FieldTerminalPath{selector: AlertInfo_FieldPathSelectorObservedValues}) 389 return res 390 } 391 392 func (fieldMask *Alert_Info_FieldMask) String() string { 393 if fieldMask == nil { 394 return "<nil>" 395 } 396 pathsStr := make([]string, 0, len(fieldMask.Paths)) 397 for _, path := range fieldMask.Paths { 398 pathsStr = append(pathsStr, path.String()) 399 } 400 return strings.Join(pathsStr, ", ") 401 } 402 403 func (fieldMask *Alert_Info_FieldMask) IsFull() bool { 404 if fieldMask == nil { 405 return false 406 } 407 presentSelectors := make([]bool, 2) 408 for _, path := range fieldMask.Paths { 409 if asFinal, ok := path.(*AlertInfo_FieldTerminalPath); ok { 410 presentSelectors[int(asFinal.selector)] = true 411 } 412 } 413 for _, flag := range presentSelectors { 414 if !flag { 415 return false 416 } 417 } 418 return true 419 } 420 421 func (fieldMask *Alert_Info_FieldMask) ProtoReflect() preflect.Message { 422 return gotenobject.MakeFieldMaskReflection(fieldMask, func(raw string) (gotenobject.FieldPath, error) { 423 return ParseAlertInfo_FieldPath(raw) 424 }) 425 } 426 427 func (fieldMask *Alert_Info_FieldMask) ProtoMessage() {} 428 429 func (fieldMask *Alert_Info_FieldMask) Reset() { 430 if fieldMask != nil { 431 fieldMask.Paths = nil 432 } 433 } 434 435 func (fieldMask *Alert_Info_FieldMask) Subtract(other *Alert_Info_FieldMask) *Alert_Info_FieldMask { 436 result := &Alert_Info_FieldMask{} 437 removedSelectors := make([]bool, 2) 438 otherSubMasks := map[AlertInfo_FieldPathSelector]gotenobject.FieldMask{ 439 AlertInfo_FieldPathSelectorTimeSerie: &Alert_Info_TimeSerie_FieldMask{}, 440 AlertInfo_FieldPathSelectorObservedValues: &Alert_Info_ObservedValues_FieldMask{}, 441 } 442 mySubMasks := map[AlertInfo_FieldPathSelector]gotenobject.FieldMask{ 443 AlertInfo_FieldPathSelectorTimeSerie: &Alert_Info_TimeSerie_FieldMask{}, 444 AlertInfo_FieldPathSelectorObservedValues: &Alert_Info_ObservedValues_FieldMask{}, 445 } 446 447 for _, path := range other.GetPaths() { 448 switch tp := path.(type) { 449 case *AlertInfo_FieldTerminalPath: 450 removedSelectors[int(tp.selector)] = true 451 case *AlertInfo_FieldSubPath: 452 otherSubMasks[tp.selector].AppendRawPath(tp.subPath) 453 } 454 } 455 for _, path := range fieldMask.GetPaths() { 456 if !removedSelectors[int(path.Selector())] { 457 if otherSubMask := otherSubMasks[path.Selector()]; otherSubMask != nil && otherSubMask.PathsCount() > 0 { 458 if tp, ok := path.(*AlertInfo_FieldTerminalPath); ok { 459 switch tp.selector { 460 case AlertInfo_FieldPathSelectorTimeSerie: 461 mySubMasks[AlertInfo_FieldPathSelectorTimeSerie] = FullAlert_Info_TimeSerie_FieldMask() 462 case AlertInfo_FieldPathSelectorObservedValues: 463 mySubMasks[AlertInfo_FieldPathSelectorObservedValues] = FullAlert_Info_ObservedValues_FieldMask() 464 } 465 } else if tp, ok := path.(*AlertInfo_FieldSubPath); ok { 466 mySubMasks[tp.selector].AppendRawPath(tp.subPath) 467 } 468 } else { 469 result.Paths = append(result.Paths, path) 470 } 471 } 472 } 473 for selector, mySubMask := range mySubMasks { 474 if mySubMask.PathsCount() > 0 { 475 for _, allowedPath := range mySubMask.SubtractRaw(otherSubMasks[selector]).GetRawPaths() { 476 result.Paths = append(result.Paths, &AlertInfo_FieldSubPath{selector: selector, subPath: allowedPath}) 477 } 478 } 479 } 480 481 if len(result.Paths) == 0 { 482 return nil 483 } 484 return result 485 } 486 487 func (fieldMask *Alert_Info_FieldMask) SubtractRaw(other gotenobject.FieldMask) gotenobject.FieldMask { 488 return fieldMask.Subtract(other.(*Alert_Info_FieldMask)) 489 } 490 491 // FilterInputFields generates copy of field paths with output_only field paths removed 492 func (fieldMask *Alert_Info_FieldMask) FilterInputFields() *Alert_Info_FieldMask { 493 result := &Alert_Info_FieldMask{} 494 for _, path := range fieldMask.Paths { 495 switch path.Selector() { 496 case AlertInfo_FieldPathSelectorTimeSerie: 497 if _, ok := path.(*AlertInfo_FieldTerminalPath); ok { 498 for _, subpath := range FullAlert_Info_TimeSerie_FieldMask().FilterInputFields().Paths { 499 result.Paths = append(result.Paths, &AlertInfo_FieldSubPath{selector: path.Selector(), subPath: subpath}) 500 } 501 } else if sub, ok := path.(*AlertInfo_FieldSubPath); ok { 502 selectedMask := &Alert_Info_TimeSerie_FieldMask{ 503 Paths: []AlertInfoTimeSerie_FieldPath{sub.subPath.(AlertInfoTimeSerie_FieldPath)}, 504 } 505 for _, allowedPath := range selectedMask.FilterInputFields().Paths { 506 result.Paths = append(result.Paths, &AlertInfo_FieldSubPath{selector: AlertInfo_FieldPathSelectorTimeSerie, subPath: allowedPath}) 507 } 508 } 509 default: 510 result.Paths = append(result.Paths, path) 511 } 512 } 513 return result 514 } 515 516 // ToFieldMask is used for proto conversions 517 func (fieldMask *Alert_Info_FieldMask) ToProtoFieldMask() *googlefieldmaskpb.FieldMask { 518 protoFieldMask := &googlefieldmaskpb.FieldMask{} 519 for _, path := range fieldMask.Paths { 520 protoFieldMask.Paths = append(protoFieldMask.Paths, path.String()) 521 } 522 return protoFieldMask 523 } 524 525 func (fieldMask *Alert_Info_FieldMask) FromProtoFieldMask(protoFieldMask *googlefieldmaskpb.FieldMask) error { 526 if fieldMask == nil { 527 return status.Error(codes.Internal, "target field mask is nil") 528 } 529 fieldMask.Paths = make([]AlertInfo_FieldPath, 0, len(protoFieldMask.Paths)) 530 for _, strPath := range protoFieldMask.Paths { 531 path, err := ParseAlertInfo_FieldPath(strPath) 532 if err != nil { 533 return err 534 } 535 fieldMask.Paths = append(fieldMask.Paths, path) 536 } 537 return nil 538 } 539 540 // implement methods required by customType 541 func (fieldMask Alert_Info_FieldMask) Marshal() ([]byte, error) { 542 protoFieldMask := fieldMask.ToProtoFieldMask() 543 return proto.Marshal(protoFieldMask) 544 } 545 546 func (fieldMask *Alert_Info_FieldMask) Unmarshal(data []byte) error { 547 protoFieldMask := &googlefieldmaskpb.FieldMask{} 548 if err := proto.Unmarshal(data, protoFieldMask); err != nil { 549 return err 550 } 551 if err := fieldMask.FromProtoFieldMask(protoFieldMask); err != nil { 552 return err 553 } 554 return nil 555 } 556 557 func (fieldMask *Alert_Info_FieldMask) Size() int { 558 return proto.Size(fieldMask.ToProtoFieldMask()) 559 } 560 561 func (fieldMask Alert_Info_FieldMask) MarshalJSON() ([]byte, error) { 562 return json.Marshal(fieldMask.ToProtoFieldMask()) 563 } 564 565 func (fieldMask *Alert_Info_FieldMask) UnmarshalJSON(data []byte) error { 566 protoFieldMask := &googlefieldmaskpb.FieldMask{} 567 if err := json.Unmarshal(data, protoFieldMask); err != nil { 568 return err 569 } 570 if err := fieldMask.FromProtoFieldMask(protoFieldMask); err != nil { 571 return err 572 } 573 return nil 574 } 575 576 func (fieldMask *Alert_Info_FieldMask) AppendPath(path AlertInfo_FieldPath) { 577 fieldMask.Paths = append(fieldMask.Paths, path) 578 } 579 580 func (fieldMask *Alert_Info_FieldMask) AppendRawPath(path gotenobject.FieldPath) { 581 fieldMask.Paths = append(fieldMask.Paths, path.(AlertInfo_FieldPath)) 582 } 583 584 func (fieldMask *Alert_Info_FieldMask) GetPaths() []AlertInfo_FieldPath { 585 if fieldMask == nil { 586 return nil 587 } 588 return fieldMask.Paths 589 } 590 591 func (fieldMask *Alert_Info_FieldMask) GetRawPaths() []gotenobject.FieldPath { 592 if fieldMask == nil { 593 return nil 594 } 595 rawPaths := make([]gotenobject.FieldPath, 0, len(fieldMask.Paths)) 596 for _, path := range fieldMask.Paths { 597 rawPaths = append(rawPaths, path) 598 } 599 return rawPaths 600 } 601 602 func (fieldMask *Alert_Info_FieldMask) SetFromCliFlag(raw string) error { 603 path, err := ParseAlertInfo_FieldPath(raw) 604 if err != nil { 605 return err 606 } 607 fieldMask.Paths = append(fieldMask.Paths, path) 608 return nil 609 } 610 611 func (fieldMask *Alert_Info_FieldMask) Set(target, source *Alert_Info) { 612 for _, path := range fieldMask.Paths { 613 val, _ := path.GetSingle(source) 614 // if val is nil, then field does not exist in source, skip 615 // otherwise, process (can still reflect.ValueOf(val).IsNil!) 616 if val != nil { 617 path.WithIValue(val).SetTo(&target) 618 } 619 } 620 } 621 622 func (fieldMask *Alert_Info_FieldMask) SetRaw(target, source gotenobject.GotenObjectExt) { 623 fieldMask.Set(target.(*Alert_Info), source.(*Alert_Info)) 624 } 625 626 func (fieldMask *Alert_Info_FieldMask) Project(source *Alert_Info) *Alert_Info { 627 if source == nil { 628 return nil 629 } 630 if fieldMask == nil { 631 return source 632 } 633 result := &Alert_Info{} 634 timeSerieMask := &Alert_Info_TimeSerie_FieldMask{} 635 wholeTimeSerieAccepted := false 636 observedValuesMask := &Alert_Info_ObservedValues_FieldMask{} 637 wholeObservedValuesAccepted := false 638 639 for _, p := range fieldMask.Paths { 640 switch tp := p.(type) { 641 case *AlertInfo_FieldTerminalPath: 642 switch tp.selector { 643 case AlertInfo_FieldPathSelectorTimeSerie: 644 result.TimeSerie = source.TimeSerie 645 wholeTimeSerieAccepted = true 646 case AlertInfo_FieldPathSelectorObservedValues: 647 result.ObservedValues = source.ObservedValues 648 wholeObservedValuesAccepted = true 649 } 650 case *AlertInfo_FieldSubPath: 651 switch tp.selector { 652 case AlertInfo_FieldPathSelectorTimeSerie: 653 timeSerieMask.AppendPath(tp.subPath.(AlertInfoTimeSerie_FieldPath)) 654 case AlertInfo_FieldPathSelectorObservedValues: 655 observedValuesMask.AppendPath(tp.subPath.(AlertInfoObservedValues_FieldPath)) 656 } 657 } 658 } 659 if wholeTimeSerieAccepted == false && len(timeSerieMask.Paths) > 0 { 660 result.TimeSerie = timeSerieMask.Project(source.GetTimeSerie()) 661 } 662 if wholeObservedValuesAccepted == false && len(observedValuesMask.Paths) > 0 { 663 result.ObservedValues = observedValuesMask.Project(source.GetObservedValues()) 664 } 665 return result 666 } 667 668 func (fieldMask *Alert_Info_FieldMask) ProjectRaw(source gotenobject.GotenObjectExt) gotenobject.GotenObjectExt { 669 return fieldMask.Project(source.(*Alert_Info)) 670 } 671 672 func (fieldMask *Alert_Info_FieldMask) PathsCount() int { 673 if fieldMask == nil { 674 return 0 675 } 676 return len(fieldMask.Paths) 677 } 678 679 type Alert_State_FieldMask struct { 680 Paths []AlertState_FieldPath 681 } 682 683 func FullAlert_State_FieldMask() *Alert_State_FieldMask { 684 res := &Alert_State_FieldMask{} 685 res.Paths = append(res.Paths, &AlertState_FieldTerminalPath{selector: AlertState_FieldPathSelectorIsFiring}) 686 res.Paths = append(res.Paths, &AlertState_FieldTerminalPath{selector: AlertState_FieldPathSelectorIsAcknowledged}) 687 res.Paths = append(res.Paths, &AlertState_FieldTerminalPath{selector: AlertState_FieldPathSelectorIsSilenced}) 688 res.Paths = append(res.Paths, &AlertState_FieldTerminalPath{selector: AlertState_FieldPathSelectorLifetime}) 689 res.Paths = append(res.Paths, &AlertState_FieldTerminalPath{selector: AlertState_FieldPathSelectorNeedsNotification}) 690 res.Paths = append(res.Paths, &AlertState_FieldTerminalPath{selector: AlertState_FieldPathSelectorNotificationCreated}) 691 res.Paths = append(res.Paths, &AlertState_FieldTerminalPath{selector: AlertState_FieldPathSelectorLifecycleCompleted}) 692 return res 693 } 694 695 func (fieldMask *Alert_State_FieldMask) String() string { 696 if fieldMask == nil { 697 return "<nil>" 698 } 699 pathsStr := make([]string, 0, len(fieldMask.Paths)) 700 for _, path := range fieldMask.Paths { 701 pathsStr = append(pathsStr, path.String()) 702 } 703 return strings.Join(pathsStr, ", ") 704 } 705 706 func (fieldMask *Alert_State_FieldMask) IsFull() bool { 707 if fieldMask == nil { 708 return false 709 } 710 presentSelectors := make([]bool, 7) 711 for _, path := range fieldMask.Paths { 712 if asFinal, ok := path.(*AlertState_FieldTerminalPath); ok { 713 presentSelectors[int(asFinal.selector)] = true 714 } 715 } 716 for _, flag := range presentSelectors { 717 if !flag { 718 return false 719 } 720 } 721 return true 722 } 723 724 func (fieldMask *Alert_State_FieldMask) ProtoReflect() preflect.Message { 725 return gotenobject.MakeFieldMaskReflection(fieldMask, func(raw string) (gotenobject.FieldPath, error) { 726 return ParseAlertState_FieldPath(raw) 727 }) 728 } 729 730 func (fieldMask *Alert_State_FieldMask) ProtoMessage() {} 731 732 func (fieldMask *Alert_State_FieldMask) Reset() { 733 if fieldMask != nil { 734 fieldMask.Paths = nil 735 } 736 } 737 738 func (fieldMask *Alert_State_FieldMask) Subtract(other *Alert_State_FieldMask) *Alert_State_FieldMask { 739 result := &Alert_State_FieldMask{} 740 removedSelectors := make([]bool, 7) 741 otherSubMasks := map[AlertState_FieldPathSelector]gotenobject.FieldMask{ 742 AlertState_FieldPathSelectorLifetime: &common.TimeRange_FieldMask{}, 743 } 744 mySubMasks := map[AlertState_FieldPathSelector]gotenobject.FieldMask{ 745 AlertState_FieldPathSelectorLifetime: &common.TimeRange_FieldMask{}, 746 } 747 748 for _, path := range other.GetPaths() { 749 switch tp := path.(type) { 750 case *AlertState_FieldTerminalPath: 751 removedSelectors[int(tp.selector)] = true 752 case *AlertState_FieldSubPath: 753 otherSubMasks[tp.selector].AppendRawPath(tp.subPath) 754 } 755 } 756 for _, path := range fieldMask.GetPaths() { 757 if !removedSelectors[int(path.Selector())] { 758 if otherSubMask := otherSubMasks[path.Selector()]; otherSubMask != nil && otherSubMask.PathsCount() > 0 { 759 if tp, ok := path.(*AlertState_FieldTerminalPath); ok { 760 switch tp.selector { 761 case AlertState_FieldPathSelectorLifetime: 762 mySubMasks[AlertState_FieldPathSelectorLifetime] = common.FullTimeRange_FieldMask() 763 } 764 } else if tp, ok := path.(*AlertState_FieldSubPath); ok { 765 mySubMasks[tp.selector].AppendRawPath(tp.subPath) 766 } 767 } else { 768 result.Paths = append(result.Paths, path) 769 } 770 } 771 } 772 for selector, mySubMask := range mySubMasks { 773 if mySubMask.PathsCount() > 0 { 774 for _, allowedPath := range mySubMask.SubtractRaw(otherSubMasks[selector]).GetRawPaths() { 775 result.Paths = append(result.Paths, &AlertState_FieldSubPath{selector: selector, subPath: allowedPath}) 776 } 777 } 778 } 779 780 if len(result.Paths) == 0 { 781 return nil 782 } 783 return result 784 } 785 786 func (fieldMask *Alert_State_FieldMask) SubtractRaw(other gotenobject.FieldMask) gotenobject.FieldMask { 787 return fieldMask.Subtract(other.(*Alert_State_FieldMask)) 788 } 789 790 // FilterInputFields generates copy of field paths with output_only field paths removed 791 func (fieldMask *Alert_State_FieldMask) FilterInputFields() *Alert_State_FieldMask { 792 result := &Alert_State_FieldMask{} 793 result.Paths = append(result.Paths, fieldMask.Paths...) 794 return result 795 } 796 797 // ToFieldMask is used for proto conversions 798 func (fieldMask *Alert_State_FieldMask) ToProtoFieldMask() *googlefieldmaskpb.FieldMask { 799 protoFieldMask := &googlefieldmaskpb.FieldMask{} 800 for _, path := range fieldMask.Paths { 801 protoFieldMask.Paths = append(protoFieldMask.Paths, path.String()) 802 } 803 return protoFieldMask 804 } 805 806 func (fieldMask *Alert_State_FieldMask) FromProtoFieldMask(protoFieldMask *googlefieldmaskpb.FieldMask) error { 807 if fieldMask == nil { 808 return status.Error(codes.Internal, "target field mask is nil") 809 } 810 fieldMask.Paths = make([]AlertState_FieldPath, 0, len(protoFieldMask.Paths)) 811 for _, strPath := range protoFieldMask.Paths { 812 path, err := ParseAlertState_FieldPath(strPath) 813 if err != nil { 814 return err 815 } 816 fieldMask.Paths = append(fieldMask.Paths, path) 817 } 818 return nil 819 } 820 821 // implement methods required by customType 822 func (fieldMask Alert_State_FieldMask) Marshal() ([]byte, error) { 823 protoFieldMask := fieldMask.ToProtoFieldMask() 824 return proto.Marshal(protoFieldMask) 825 } 826 827 func (fieldMask *Alert_State_FieldMask) Unmarshal(data []byte) error { 828 protoFieldMask := &googlefieldmaskpb.FieldMask{} 829 if err := proto.Unmarshal(data, protoFieldMask); err != nil { 830 return err 831 } 832 if err := fieldMask.FromProtoFieldMask(protoFieldMask); err != nil { 833 return err 834 } 835 return nil 836 } 837 838 func (fieldMask *Alert_State_FieldMask) Size() int { 839 return proto.Size(fieldMask.ToProtoFieldMask()) 840 } 841 842 func (fieldMask Alert_State_FieldMask) MarshalJSON() ([]byte, error) { 843 return json.Marshal(fieldMask.ToProtoFieldMask()) 844 } 845 846 func (fieldMask *Alert_State_FieldMask) UnmarshalJSON(data []byte) error { 847 protoFieldMask := &googlefieldmaskpb.FieldMask{} 848 if err := json.Unmarshal(data, protoFieldMask); err != nil { 849 return err 850 } 851 if err := fieldMask.FromProtoFieldMask(protoFieldMask); err != nil { 852 return err 853 } 854 return nil 855 } 856 857 func (fieldMask *Alert_State_FieldMask) AppendPath(path AlertState_FieldPath) { 858 fieldMask.Paths = append(fieldMask.Paths, path) 859 } 860 861 func (fieldMask *Alert_State_FieldMask) AppendRawPath(path gotenobject.FieldPath) { 862 fieldMask.Paths = append(fieldMask.Paths, path.(AlertState_FieldPath)) 863 } 864 865 func (fieldMask *Alert_State_FieldMask) GetPaths() []AlertState_FieldPath { 866 if fieldMask == nil { 867 return nil 868 } 869 return fieldMask.Paths 870 } 871 872 func (fieldMask *Alert_State_FieldMask) GetRawPaths() []gotenobject.FieldPath { 873 if fieldMask == nil { 874 return nil 875 } 876 rawPaths := make([]gotenobject.FieldPath, 0, len(fieldMask.Paths)) 877 for _, path := range fieldMask.Paths { 878 rawPaths = append(rawPaths, path) 879 } 880 return rawPaths 881 } 882 883 func (fieldMask *Alert_State_FieldMask) SetFromCliFlag(raw string) error { 884 path, err := ParseAlertState_FieldPath(raw) 885 if err != nil { 886 return err 887 } 888 fieldMask.Paths = append(fieldMask.Paths, path) 889 return nil 890 } 891 892 func (fieldMask *Alert_State_FieldMask) Set(target, source *Alert_State) { 893 for _, path := range fieldMask.Paths { 894 val, _ := path.GetSingle(source) 895 // if val is nil, then field does not exist in source, skip 896 // otherwise, process (can still reflect.ValueOf(val).IsNil!) 897 if val != nil { 898 path.WithIValue(val).SetTo(&target) 899 } 900 } 901 } 902 903 func (fieldMask *Alert_State_FieldMask) SetRaw(target, source gotenobject.GotenObjectExt) { 904 fieldMask.Set(target.(*Alert_State), source.(*Alert_State)) 905 } 906 907 func (fieldMask *Alert_State_FieldMask) Project(source *Alert_State) *Alert_State { 908 if source == nil { 909 return nil 910 } 911 if fieldMask == nil { 912 return source 913 } 914 result := &Alert_State{} 915 lifetimeMask := &common.TimeRange_FieldMask{} 916 wholeLifetimeAccepted := false 917 918 for _, p := range fieldMask.Paths { 919 switch tp := p.(type) { 920 case *AlertState_FieldTerminalPath: 921 switch tp.selector { 922 case AlertState_FieldPathSelectorIsFiring: 923 result.IsFiring = source.IsFiring 924 case AlertState_FieldPathSelectorIsAcknowledged: 925 result.IsAcknowledged = source.IsAcknowledged 926 case AlertState_FieldPathSelectorIsSilenced: 927 result.IsSilenced = source.IsSilenced 928 case AlertState_FieldPathSelectorLifetime: 929 result.Lifetime = source.Lifetime 930 wholeLifetimeAccepted = true 931 case AlertState_FieldPathSelectorNeedsNotification: 932 result.NeedsNotification = source.NeedsNotification 933 case AlertState_FieldPathSelectorNotificationCreated: 934 result.NotificationCreated = source.NotificationCreated 935 case AlertState_FieldPathSelectorLifecycleCompleted: 936 result.LifecycleCompleted = source.LifecycleCompleted 937 } 938 case *AlertState_FieldSubPath: 939 switch tp.selector { 940 case AlertState_FieldPathSelectorLifetime: 941 lifetimeMask.AppendPath(tp.subPath.(common.TimeRange_FieldPath)) 942 } 943 } 944 } 945 if wholeLifetimeAccepted == false && len(lifetimeMask.Paths) > 0 { 946 result.Lifetime = lifetimeMask.Project(source.GetLifetime()) 947 } 948 return result 949 } 950 951 func (fieldMask *Alert_State_FieldMask) ProjectRaw(source gotenobject.GotenObjectExt) gotenobject.GotenObjectExt { 952 return fieldMask.Project(source.(*Alert_State)) 953 } 954 955 func (fieldMask *Alert_State_FieldMask) PathsCount() int { 956 if fieldMask == nil { 957 return 0 958 } 959 return len(fieldMask.Paths) 960 } 961 962 type Alert_Info_TimeSerie_FieldMask struct { 963 Paths []AlertInfoTimeSerie_FieldPath 964 } 965 966 func FullAlert_Info_TimeSerie_FieldMask() *Alert_Info_TimeSerie_FieldMask { 967 res := &Alert_Info_TimeSerie_FieldMask{} 968 res.Paths = append(res.Paths, &AlertInfoTimeSerie_FieldTerminalPath{selector: AlertInfoTimeSerie_FieldPathSelectorKey}) 969 res.Paths = append(res.Paths, &AlertInfoTimeSerie_FieldTerminalPath{selector: AlertInfoTimeSerie_FieldPathSelectorMetric}) 970 res.Paths = append(res.Paths, &AlertInfoTimeSerie_FieldTerminalPath{selector: AlertInfoTimeSerie_FieldPathSelectorMonitoredResource}) 971 res.Paths = append(res.Paths, &AlertInfoTimeSerie_FieldTerminalPath{selector: AlertInfoTimeSerie_FieldPathSelectorData}) 972 res.Paths = append(res.Paths, &AlertInfoTimeSerie_FieldTerminalPath{selector: AlertInfoTimeSerie_FieldPathSelectorBinData}) 973 return res 974 } 975 976 func (fieldMask *Alert_Info_TimeSerie_FieldMask) String() string { 977 if fieldMask == nil { 978 return "<nil>" 979 } 980 pathsStr := make([]string, 0, len(fieldMask.Paths)) 981 for _, path := range fieldMask.Paths { 982 pathsStr = append(pathsStr, path.String()) 983 } 984 return strings.Join(pathsStr, ", ") 985 } 986 987 func (fieldMask *Alert_Info_TimeSerie_FieldMask) IsFull() bool { 988 if fieldMask == nil { 989 return false 990 } 991 presentSelectors := make([]bool, 5) 992 for _, path := range fieldMask.Paths { 993 if asFinal, ok := path.(*AlertInfoTimeSerie_FieldTerminalPath); ok { 994 presentSelectors[int(asFinal.selector)] = true 995 } 996 } 997 for _, flag := range presentSelectors { 998 if !flag { 999 return false 1000 } 1001 } 1002 return true 1003 } 1004 1005 func (fieldMask *Alert_Info_TimeSerie_FieldMask) ProtoReflect() preflect.Message { 1006 return gotenobject.MakeFieldMaskReflection(fieldMask, func(raw string) (gotenobject.FieldPath, error) { 1007 return ParseAlertInfoTimeSerie_FieldPath(raw) 1008 }) 1009 } 1010 1011 func (fieldMask *Alert_Info_TimeSerie_FieldMask) ProtoMessage() {} 1012 1013 func (fieldMask *Alert_Info_TimeSerie_FieldMask) Reset() { 1014 if fieldMask != nil { 1015 fieldMask.Paths = nil 1016 } 1017 } 1018 1019 func (fieldMask *Alert_Info_TimeSerie_FieldMask) Subtract(other *Alert_Info_TimeSerie_FieldMask) *Alert_Info_TimeSerie_FieldMask { 1020 result := &Alert_Info_TimeSerie_FieldMask{} 1021 removedSelectors := make([]bool, 5) 1022 otherSubMasks := map[AlertInfoTimeSerie_FieldPathSelector]gotenobject.FieldMask{ 1023 AlertInfoTimeSerie_FieldPathSelectorMetric: &common.Metric_FieldMask{}, 1024 AlertInfoTimeSerie_FieldPathSelectorMonitoredResource: &common.MonitoredResource_FieldMask{}, 1025 } 1026 mySubMasks := map[AlertInfoTimeSerie_FieldPathSelector]gotenobject.FieldMask{ 1027 AlertInfoTimeSerie_FieldPathSelectorMetric: &common.Metric_FieldMask{}, 1028 AlertInfoTimeSerie_FieldPathSelectorMonitoredResource: &common.MonitoredResource_FieldMask{}, 1029 } 1030 1031 for _, path := range other.GetPaths() { 1032 switch tp := path.(type) { 1033 case *AlertInfoTimeSerie_FieldTerminalPath: 1034 removedSelectors[int(tp.selector)] = true 1035 case *AlertInfoTimeSerie_FieldSubPath: 1036 otherSubMasks[tp.selector].AppendRawPath(tp.subPath) 1037 } 1038 } 1039 for _, path := range fieldMask.GetPaths() { 1040 if !removedSelectors[int(path.Selector())] { 1041 if otherSubMask := otherSubMasks[path.Selector()]; otherSubMask != nil && otherSubMask.PathsCount() > 0 { 1042 if tp, ok := path.(*AlertInfoTimeSerie_FieldTerminalPath); ok { 1043 switch tp.selector { 1044 case AlertInfoTimeSerie_FieldPathSelectorMetric: 1045 mySubMasks[AlertInfoTimeSerie_FieldPathSelectorMetric] = common.FullMetric_FieldMask() 1046 case AlertInfoTimeSerie_FieldPathSelectorMonitoredResource: 1047 mySubMasks[AlertInfoTimeSerie_FieldPathSelectorMonitoredResource] = common.FullMonitoredResource_FieldMask() 1048 } 1049 } else if tp, ok := path.(*AlertInfoTimeSerie_FieldSubPath); ok { 1050 mySubMasks[tp.selector].AppendRawPath(tp.subPath) 1051 } 1052 } else { 1053 result.Paths = append(result.Paths, path) 1054 } 1055 } 1056 } 1057 for selector, mySubMask := range mySubMasks { 1058 if mySubMask.PathsCount() > 0 { 1059 for _, allowedPath := range mySubMask.SubtractRaw(otherSubMasks[selector]).GetRawPaths() { 1060 result.Paths = append(result.Paths, &AlertInfoTimeSerie_FieldSubPath{selector: selector, subPath: allowedPath}) 1061 } 1062 } 1063 } 1064 1065 if len(result.Paths) == 0 { 1066 return nil 1067 } 1068 return result 1069 } 1070 1071 func (fieldMask *Alert_Info_TimeSerie_FieldMask) SubtractRaw(other gotenobject.FieldMask) gotenobject.FieldMask { 1072 return fieldMask.Subtract(other.(*Alert_Info_TimeSerie_FieldMask)) 1073 } 1074 1075 // FilterInputFields generates copy of field paths with output_only field paths removed 1076 func (fieldMask *Alert_Info_TimeSerie_FieldMask) FilterInputFields() *Alert_Info_TimeSerie_FieldMask { 1077 result := &Alert_Info_TimeSerie_FieldMask{} 1078 for _, path := range fieldMask.Paths { 1079 switch path.Selector() { 1080 case AlertInfoTimeSerie_FieldPathSelectorMetric: 1081 case AlertInfoTimeSerie_FieldPathSelectorMonitoredResource: 1082 case AlertInfoTimeSerie_FieldPathSelectorData: 1083 case AlertInfoTimeSerie_FieldPathSelectorBinData: 1084 default: 1085 result.Paths = append(result.Paths, path) 1086 } 1087 } 1088 return result 1089 } 1090 1091 // ToFieldMask is used for proto conversions 1092 func (fieldMask *Alert_Info_TimeSerie_FieldMask) ToProtoFieldMask() *googlefieldmaskpb.FieldMask { 1093 protoFieldMask := &googlefieldmaskpb.FieldMask{} 1094 for _, path := range fieldMask.Paths { 1095 protoFieldMask.Paths = append(protoFieldMask.Paths, path.String()) 1096 } 1097 return protoFieldMask 1098 } 1099 1100 func (fieldMask *Alert_Info_TimeSerie_FieldMask) FromProtoFieldMask(protoFieldMask *googlefieldmaskpb.FieldMask) error { 1101 if fieldMask == nil { 1102 return status.Error(codes.Internal, "target field mask is nil") 1103 } 1104 fieldMask.Paths = make([]AlertInfoTimeSerie_FieldPath, 0, len(protoFieldMask.Paths)) 1105 for _, strPath := range protoFieldMask.Paths { 1106 path, err := ParseAlertInfoTimeSerie_FieldPath(strPath) 1107 if err != nil { 1108 return err 1109 } 1110 fieldMask.Paths = append(fieldMask.Paths, path) 1111 } 1112 return nil 1113 } 1114 1115 // implement methods required by customType 1116 func (fieldMask Alert_Info_TimeSerie_FieldMask) Marshal() ([]byte, error) { 1117 protoFieldMask := fieldMask.ToProtoFieldMask() 1118 return proto.Marshal(protoFieldMask) 1119 } 1120 1121 func (fieldMask *Alert_Info_TimeSerie_FieldMask) Unmarshal(data []byte) error { 1122 protoFieldMask := &googlefieldmaskpb.FieldMask{} 1123 if err := proto.Unmarshal(data, protoFieldMask); err != nil { 1124 return err 1125 } 1126 if err := fieldMask.FromProtoFieldMask(protoFieldMask); err != nil { 1127 return err 1128 } 1129 return nil 1130 } 1131 1132 func (fieldMask *Alert_Info_TimeSerie_FieldMask) Size() int { 1133 return proto.Size(fieldMask.ToProtoFieldMask()) 1134 } 1135 1136 func (fieldMask Alert_Info_TimeSerie_FieldMask) MarshalJSON() ([]byte, error) { 1137 return json.Marshal(fieldMask.ToProtoFieldMask()) 1138 } 1139 1140 func (fieldMask *Alert_Info_TimeSerie_FieldMask) UnmarshalJSON(data []byte) error { 1141 protoFieldMask := &googlefieldmaskpb.FieldMask{} 1142 if err := json.Unmarshal(data, protoFieldMask); err != nil { 1143 return err 1144 } 1145 if err := fieldMask.FromProtoFieldMask(protoFieldMask); err != nil { 1146 return err 1147 } 1148 return nil 1149 } 1150 1151 func (fieldMask *Alert_Info_TimeSerie_FieldMask) AppendPath(path AlertInfoTimeSerie_FieldPath) { 1152 fieldMask.Paths = append(fieldMask.Paths, path) 1153 } 1154 1155 func (fieldMask *Alert_Info_TimeSerie_FieldMask) AppendRawPath(path gotenobject.FieldPath) { 1156 fieldMask.Paths = append(fieldMask.Paths, path.(AlertInfoTimeSerie_FieldPath)) 1157 } 1158 1159 func (fieldMask *Alert_Info_TimeSerie_FieldMask) GetPaths() []AlertInfoTimeSerie_FieldPath { 1160 if fieldMask == nil { 1161 return nil 1162 } 1163 return fieldMask.Paths 1164 } 1165 1166 func (fieldMask *Alert_Info_TimeSerie_FieldMask) GetRawPaths() []gotenobject.FieldPath { 1167 if fieldMask == nil { 1168 return nil 1169 } 1170 rawPaths := make([]gotenobject.FieldPath, 0, len(fieldMask.Paths)) 1171 for _, path := range fieldMask.Paths { 1172 rawPaths = append(rawPaths, path) 1173 } 1174 return rawPaths 1175 } 1176 1177 func (fieldMask *Alert_Info_TimeSerie_FieldMask) SetFromCliFlag(raw string) error { 1178 path, err := ParseAlertInfoTimeSerie_FieldPath(raw) 1179 if err != nil { 1180 return err 1181 } 1182 fieldMask.Paths = append(fieldMask.Paths, path) 1183 return nil 1184 } 1185 1186 func (fieldMask *Alert_Info_TimeSerie_FieldMask) Set(target, source *Alert_Info_TimeSerie) { 1187 for _, path := range fieldMask.Paths { 1188 val, _ := path.GetSingle(source) 1189 // if val is nil, then field does not exist in source, skip 1190 // otherwise, process (can still reflect.ValueOf(val).IsNil!) 1191 if val != nil { 1192 path.WithIValue(val).SetTo(&target) 1193 } 1194 } 1195 } 1196 1197 func (fieldMask *Alert_Info_TimeSerie_FieldMask) SetRaw(target, source gotenobject.GotenObjectExt) { 1198 fieldMask.Set(target.(*Alert_Info_TimeSerie), source.(*Alert_Info_TimeSerie)) 1199 } 1200 1201 func (fieldMask *Alert_Info_TimeSerie_FieldMask) Project(source *Alert_Info_TimeSerie) *Alert_Info_TimeSerie { 1202 if source == nil { 1203 return nil 1204 } 1205 if fieldMask == nil { 1206 return source 1207 } 1208 result := &Alert_Info_TimeSerie{} 1209 metricMask := &common.Metric_FieldMask{} 1210 wholeMetricAccepted := false 1211 monitoredResourceMask := &common.MonitoredResource_FieldMask{} 1212 wholeMonitoredResourceAccepted := false 1213 1214 for _, p := range fieldMask.Paths { 1215 switch tp := p.(type) { 1216 case *AlertInfoTimeSerie_FieldTerminalPath: 1217 switch tp.selector { 1218 case AlertInfoTimeSerie_FieldPathSelectorKey: 1219 result.Key = source.Key 1220 case AlertInfoTimeSerie_FieldPathSelectorMetric: 1221 result.Metric = source.Metric 1222 wholeMetricAccepted = true 1223 case AlertInfoTimeSerie_FieldPathSelectorMonitoredResource: 1224 result.MonitoredResource = source.MonitoredResource 1225 wholeMonitoredResourceAccepted = true 1226 case AlertInfoTimeSerie_FieldPathSelectorData: 1227 result.Data = source.Data 1228 case AlertInfoTimeSerie_FieldPathSelectorBinData: 1229 result.BinData = source.BinData 1230 } 1231 case *AlertInfoTimeSerie_FieldSubPath: 1232 switch tp.selector { 1233 case AlertInfoTimeSerie_FieldPathSelectorMetric: 1234 metricMask.AppendPath(tp.subPath.(common.Metric_FieldPath)) 1235 case AlertInfoTimeSerie_FieldPathSelectorMonitoredResource: 1236 monitoredResourceMask.AppendPath(tp.subPath.(common.MonitoredResource_FieldPath)) 1237 } 1238 } 1239 } 1240 if wholeMetricAccepted == false && len(metricMask.Paths) > 0 { 1241 result.Metric = metricMask.Project(source.GetMetric()) 1242 } 1243 if wholeMonitoredResourceAccepted == false && len(monitoredResourceMask.Paths) > 0 { 1244 result.MonitoredResource = monitoredResourceMask.Project(source.GetMonitoredResource()) 1245 } 1246 return result 1247 } 1248 1249 func (fieldMask *Alert_Info_TimeSerie_FieldMask) ProjectRaw(source gotenobject.GotenObjectExt) gotenobject.GotenObjectExt { 1250 return fieldMask.Project(source.(*Alert_Info_TimeSerie)) 1251 } 1252 1253 func (fieldMask *Alert_Info_TimeSerie_FieldMask) PathsCount() int { 1254 if fieldMask == nil { 1255 return 0 1256 } 1257 return len(fieldMask.Paths) 1258 } 1259 1260 type Alert_Info_ObservedValues_FieldMask struct { 1261 Paths []AlertInfoObservedValues_FieldPath 1262 } 1263 1264 func FullAlert_Info_ObservedValues_FieldMask() *Alert_Info_ObservedValues_FieldMask { 1265 res := &Alert_Info_ObservedValues_FieldMask{} 1266 res.Paths = append(res.Paths, &AlertInfoObservedValues_FieldTerminalPath{selector: AlertInfoObservedValues_FieldPathSelectorExampleValue}) 1267 res.Paths = append(res.Paths, &AlertInfoObservedValues_FieldTerminalPath{selector: AlertInfoObservedValues_FieldPathSelectorPerMetric}) 1268 return res 1269 } 1270 1271 func (fieldMask *Alert_Info_ObservedValues_FieldMask) String() string { 1272 if fieldMask == nil { 1273 return "<nil>" 1274 } 1275 pathsStr := make([]string, 0, len(fieldMask.Paths)) 1276 for _, path := range fieldMask.Paths { 1277 pathsStr = append(pathsStr, path.String()) 1278 } 1279 return strings.Join(pathsStr, ", ") 1280 } 1281 1282 func (fieldMask *Alert_Info_ObservedValues_FieldMask) IsFull() bool { 1283 if fieldMask == nil { 1284 return false 1285 } 1286 presentSelectors := make([]bool, 2) 1287 for _, path := range fieldMask.Paths { 1288 if asFinal, ok := path.(*AlertInfoObservedValues_FieldTerminalPath); ok { 1289 presentSelectors[int(asFinal.selector)] = true 1290 } 1291 } 1292 for _, flag := range presentSelectors { 1293 if !flag { 1294 return false 1295 } 1296 } 1297 return true 1298 } 1299 1300 func (fieldMask *Alert_Info_ObservedValues_FieldMask) ProtoReflect() preflect.Message { 1301 return gotenobject.MakeFieldMaskReflection(fieldMask, func(raw string) (gotenobject.FieldPath, error) { 1302 return ParseAlertInfoObservedValues_FieldPath(raw) 1303 }) 1304 } 1305 1306 func (fieldMask *Alert_Info_ObservedValues_FieldMask) ProtoMessage() {} 1307 1308 func (fieldMask *Alert_Info_ObservedValues_FieldMask) Reset() { 1309 if fieldMask != nil { 1310 fieldMask.Paths = nil 1311 } 1312 } 1313 1314 func (fieldMask *Alert_Info_ObservedValues_FieldMask) Subtract(other *Alert_Info_ObservedValues_FieldMask) *Alert_Info_ObservedValues_FieldMask { 1315 result := &Alert_Info_ObservedValues_FieldMask{} 1316 removedSelectors := make([]bool, 2) 1317 1318 for _, path := range other.GetPaths() { 1319 switch tp := path.(type) { 1320 case *AlertInfoObservedValues_FieldTerminalPath: 1321 removedSelectors[int(tp.selector)] = true 1322 } 1323 } 1324 for _, path := range fieldMask.GetPaths() { 1325 if !removedSelectors[int(path.Selector())] { 1326 result.Paths = append(result.Paths, path) 1327 } 1328 } 1329 1330 if len(result.Paths) == 0 { 1331 return nil 1332 } 1333 return result 1334 } 1335 1336 func (fieldMask *Alert_Info_ObservedValues_FieldMask) SubtractRaw(other gotenobject.FieldMask) gotenobject.FieldMask { 1337 return fieldMask.Subtract(other.(*Alert_Info_ObservedValues_FieldMask)) 1338 } 1339 1340 // FilterInputFields generates copy of field paths with output_only field paths removed 1341 func (fieldMask *Alert_Info_ObservedValues_FieldMask) FilterInputFields() *Alert_Info_ObservedValues_FieldMask { 1342 result := &Alert_Info_ObservedValues_FieldMask{} 1343 result.Paths = append(result.Paths, fieldMask.Paths...) 1344 return result 1345 } 1346 1347 // ToFieldMask is used for proto conversions 1348 func (fieldMask *Alert_Info_ObservedValues_FieldMask) ToProtoFieldMask() *googlefieldmaskpb.FieldMask { 1349 protoFieldMask := &googlefieldmaskpb.FieldMask{} 1350 for _, path := range fieldMask.Paths { 1351 protoFieldMask.Paths = append(protoFieldMask.Paths, path.String()) 1352 } 1353 return protoFieldMask 1354 } 1355 1356 func (fieldMask *Alert_Info_ObservedValues_FieldMask) FromProtoFieldMask(protoFieldMask *googlefieldmaskpb.FieldMask) error { 1357 if fieldMask == nil { 1358 return status.Error(codes.Internal, "target field mask is nil") 1359 } 1360 fieldMask.Paths = make([]AlertInfoObservedValues_FieldPath, 0, len(protoFieldMask.Paths)) 1361 for _, strPath := range protoFieldMask.Paths { 1362 path, err := ParseAlertInfoObservedValues_FieldPath(strPath) 1363 if err != nil { 1364 return err 1365 } 1366 fieldMask.Paths = append(fieldMask.Paths, path) 1367 } 1368 return nil 1369 } 1370 1371 // implement methods required by customType 1372 func (fieldMask Alert_Info_ObservedValues_FieldMask) Marshal() ([]byte, error) { 1373 protoFieldMask := fieldMask.ToProtoFieldMask() 1374 return proto.Marshal(protoFieldMask) 1375 } 1376 1377 func (fieldMask *Alert_Info_ObservedValues_FieldMask) Unmarshal(data []byte) error { 1378 protoFieldMask := &googlefieldmaskpb.FieldMask{} 1379 if err := proto.Unmarshal(data, protoFieldMask); err != nil { 1380 return err 1381 } 1382 if err := fieldMask.FromProtoFieldMask(protoFieldMask); err != nil { 1383 return err 1384 } 1385 return nil 1386 } 1387 1388 func (fieldMask *Alert_Info_ObservedValues_FieldMask) Size() int { 1389 return proto.Size(fieldMask.ToProtoFieldMask()) 1390 } 1391 1392 func (fieldMask Alert_Info_ObservedValues_FieldMask) MarshalJSON() ([]byte, error) { 1393 return json.Marshal(fieldMask.ToProtoFieldMask()) 1394 } 1395 1396 func (fieldMask *Alert_Info_ObservedValues_FieldMask) UnmarshalJSON(data []byte) error { 1397 protoFieldMask := &googlefieldmaskpb.FieldMask{} 1398 if err := json.Unmarshal(data, protoFieldMask); err != nil { 1399 return err 1400 } 1401 if err := fieldMask.FromProtoFieldMask(protoFieldMask); err != nil { 1402 return err 1403 } 1404 return nil 1405 } 1406 1407 func (fieldMask *Alert_Info_ObservedValues_FieldMask) AppendPath(path AlertInfoObservedValues_FieldPath) { 1408 fieldMask.Paths = append(fieldMask.Paths, path) 1409 } 1410 1411 func (fieldMask *Alert_Info_ObservedValues_FieldMask) AppendRawPath(path gotenobject.FieldPath) { 1412 fieldMask.Paths = append(fieldMask.Paths, path.(AlertInfoObservedValues_FieldPath)) 1413 } 1414 1415 func (fieldMask *Alert_Info_ObservedValues_FieldMask) GetPaths() []AlertInfoObservedValues_FieldPath { 1416 if fieldMask == nil { 1417 return nil 1418 } 1419 return fieldMask.Paths 1420 } 1421 1422 func (fieldMask *Alert_Info_ObservedValues_FieldMask) GetRawPaths() []gotenobject.FieldPath { 1423 if fieldMask == nil { 1424 return nil 1425 } 1426 rawPaths := make([]gotenobject.FieldPath, 0, len(fieldMask.Paths)) 1427 for _, path := range fieldMask.Paths { 1428 rawPaths = append(rawPaths, path) 1429 } 1430 return rawPaths 1431 } 1432 1433 func (fieldMask *Alert_Info_ObservedValues_FieldMask) SetFromCliFlag(raw string) error { 1434 path, err := ParseAlertInfoObservedValues_FieldPath(raw) 1435 if err != nil { 1436 return err 1437 } 1438 fieldMask.Paths = append(fieldMask.Paths, path) 1439 return nil 1440 } 1441 1442 func (fieldMask *Alert_Info_ObservedValues_FieldMask) Set(target, source *Alert_Info_ObservedValues) { 1443 for _, path := range fieldMask.Paths { 1444 val, _ := path.GetSingle(source) 1445 // if val is nil, then field does not exist in source, skip 1446 // otherwise, process (can still reflect.ValueOf(val).IsNil!) 1447 if val != nil { 1448 path.WithIValue(val).SetTo(&target) 1449 } 1450 } 1451 } 1452 1453 func (fieldMask *Alert_Info_ObservedValues_FieldMask) SetRaw(target, source gotenobject.GotenObjectExt) { 1454 fieldMask.Set(target.(*Alert_Info_ObservedValues), source.(*Alert_Info_ObservedValues)) 1455 } 1456 1457 func (fieldMask *Alert_Info_ObservedValues_FieldMask) Project(source *Alert_Info_ObservedValues) *Alert_Info_ObservedValues { 1458 if source == nil { 1459 return nil 1460 } 1461 if fieldMask == nil { 1462 return source 1463 } 1464 result := &Alert_Info_ObservedValues{} 1465 var perMetricMapKeys []string 1466 wholePerMetricAccepted := false 1467 1468 for _, p := range fieldMask.Paths { 1469 switch tp := p.(type) { 1470 case *AlertInfoObservedValues_FieldTerminalPath: 1471 switch tp.selector { 1472 case AlertInfoObservedValues_FieldPathSelectorExampleValue: 1473 result.ExampleValue = source.ExampleValue 1474 case AlertInfoObservedValues_FieldPathSelectorPerMetric: 1475 result.PerMetric = source.PerMetric 1476 wholePerMetricAccepted = true 1477 } 1478 case *AlertInfoObservedValues_FieldPathMap: 1479 switch tp.selector { 1480 case AlertInfoObservedValues_FieldPathSelectorPerMetric: 1481 perMetricMapKeys = append(perMetricMapKeys, tp.key) 1482 } 1483 } 1484 } 1485 if wholePerMetricAccepted == false && len(perMetricMapKeys) > 0 && source.GetPerMetric() != nil { 1486 copiedMap := map[string]float64{} 1487 sourceMap := source.GetPerMetric() 1488 for _, key := range perMetricMapKeys { 1489 copiedMap[key] = sourceMap[key] 1490 } 1491 result.PerMetric = copiedMap 1492 } 1493 return result 1494 } 1495 1496 func (fieldMask *Alert_Info_ObservedValues_FieldMask) ProjectRaw(source gotenobject.GotenObjectExt) gotenobject.GotenObjectExt { 1497 return fieldMask.Project(source.(*Alert_Info_ObservedValues)) 1498 } 1499 1500 func (fieldMask *Alert_Info_ObservedValues_FieldMask) PathsCount() int { 1501 if fieldMask == nil { 1502 return 0 1503 } 1504 return len(fieldMask.Paths) 1505 }