github.com/cloudwan/edgelq-sdk@v1.15.4/iam/resources/v1/project_invitation/project_invitation.pb.fieldmask.go (about)

     1  // Code generated by protoc-gen-goten-object
     2  // File: edgelq/iam/proto/v1/project_invitation.proto
     3  // DO NOT EDIT!!!
     4  
     5  package project_invitation
     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  	iam_invitation "github.com/cloudwan/edgelq-sdk/iam/resources/v1/invitation"
    23  	project "github.com/cloudwan/edgelq-sdk/iam/resources/v1/project"
    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  	_ = &iam_invitation.Actor{}
    44  	_ = &project.Project{}
    45  	_ = &meta.Meta{}
    46  )
    47  
    48  type ProjectInvitation_FieldMask struct {
    49  	Paths []ProjectInvitation_FieldPath
    50  }
    51  
    52  func FullProjectInvitation_FieldMask() *ProjectInvitation_FieldMask {
    53  	res := &ProjectInvitation_FieldMask{}
    54  	res.Paths = append(res.Paths, &ProjectInvitation_FieldTerminalPath{selector: ProjectInvitation_FieldPathSelectorName})
    55  	res.Paths = append(res.Paths, &ProjectInvitation_FieldTerminalPath{selector: ProjectInvitation_FieldPathSelectorMetadata})
    56  	res.Paths = append(res.Paths, &ProjectInvitation_FieldTerminalPath{selector: ProjectInvitation_FieldPathSelectorProjectDisplayName})
    57  	res.Paths = append(res.Paths, &ProjectInvitation_FieldTerminalPath{selector: ProjectInvitation_FieldPathSelectorInvitation})
    58  	return res
    59  }
    60  
    61  func (fieldMask *ProjectInvitation_FieldMask) String() string {
    62  	if fieldMask == nil {
    63  		return "<nil>"
    64  	}
    65  	pathsStr := make([]string, 0, len(fieldMask.Paths))
    66  	for _, path := range fieldMask.Paths {
    67  		pathsStr = append(pathsStr, path.String())
    68  	}
    69  	return strings.Join(pathsStr, ", ")
    70  }
    71  
    72  func (fieldMask *ProjectInvitation_FieldMask) IsFull() bool {
    73  	if fieldMask == nil {
    74  		return false
    75  	}
    76  	presentSelectors := make([]bool, 4)
    77  	for _, path := range fieldMask.Paths {
    78  		if asFinal, ok := path.(*ProjectInvitation_FieldTerminalPath); ok {
    79  			presentSelectors[int(asFinal.selector)] = true
    80  		}
    81  	}
    82  	for _, flag := range presentSelectors {
    83  		if !flag {
    84  			return false
    85  		}
    86  	}
    87  	return true
    88  }
    89  
    90  func (fieldMask *ProjectInvitation_FieldMask) ProtoReflect() preflect.Message {
    91  	return gotenobject.MakeFieldMaskReflection(fieldMask, func(raw string) (gotenobject.FieldPath, error) {
    92  		return ParseProjectInvitation_FieldPath(raw)
    93  	})
    94  }
    95  
    96  func (fieldMask *ProjectInvitation_FieldMask) ProtoMessage() {}
    97  
    98  func (fieldMask *ProjectInvitation_FieldMask) Reset() {
    99  	if fieldMask != nil {
   100  		fieldMask.Paths = nil
   101  	}
   102  }
   103  
   104  func (fieldMask *ProjectInvitation_FieldMask) Subtract(other *ProjectInvitation_FieldMask) *ProjectInvitation_FieldMask {
   105  	result := &ProjectInvitation_FieldMask{}
   106  	removedSelectors := make([]bool, 4)
   107  	otherSubMasks := map[ProjectInvitation_FieldPathSelector]gotenobject.FieldMask{
   108  		ProjectInvitation_FieldPathSelectorMetadata:   &meta.Meta_FieldMask{},
   109  		ProjectInvitation_FieldPathSelectorInvitation: &iam_invitation.Invitation_FieldMask{},
   110  	}
   111  	mySubMasks := map[ProjectInvitation_FieldPathSelector]gotenobject.FieldMask{
   112  		ProjectInvitation_FieldPathSelectorMetadata:   &meta.Meta_FieldMask{},
   113  		ProjectInvitation_FieldPathSelectorInvitation: &iam_invitation.Invitation_FieldMask{},
   114  	}
   115  
   116  	for _, path := range other.GetPaths() {
   117  		switch tp := path.(type) {
   118  		case *ProjectInvitation_FieldTerminalPath:
   119  			removedSelectors[int(tp.selector)] = true
   120  		case *ProjectInvitation_FieldSubPath:
   121  			otherSubMasks[tp.selector].AppendRawPath(tp.subPath)
   122  		}
   123  	}
   124  	for _, path := range fieldMask.GetPaths() {
   125  		if !removedSelectors[int(path.Selector())] {
   126  			if otherSubMask := otherSubMasks[path.Selector()]; otherSubMask != nil && otherSubMask.PathsCount() > 0 {
   127  				if tp, ok := path.(*ProjectInvitation_FieldTerminalPath); ok {
   128  					switch tp.selector {
   129  					case ProjectInvitation_FieldPathSelectorMetadata:
   130  						mySubMasks[ProjectInvitation_FieldPathSelectorMetadata] = meta.FullMeta_FieldMask()
   131  					case ProjectInvitation_FieldPathSelectorInvitation:
   132  						mySubMasks[ProjectInvitation_FieldPathSelectorInvitation] = iam_invitation.FullInvitation_FieldMask()
   133  					}
   134  				} else if tp, ok := path.(*ProjectInvitation_FieldSubPath); ok {
   135  					mySubMasks[tp.selector].AppendRawPath(tp.subPath)
   136  				}
   137  			} else {
   138  				result.Paths = append(result.Paths, path)
   139  			}
   140  		}
   141  	}
   142  	for selector, mySubMask := range mySubMasks {
   143  		if mySubMask.PathsCount() > 0 {
   144  			for _, allowedPath := range mySubMask.SubtractRaw(otherSubMasks[selector]).GetRawPaths() {
   145  				result.Paths = append(result.Paths, &ProjectInvitation_FieldSubPath{selector: selector, subPath: allowedPath})
   146  			}
   147  		}
   148  	}
   149  
   150  	if len(result.Paths) == 0 {
   151  		return nil
   152  	}
   153  	return result
   154  }
   155  
   156  func (fieldMask *ProjectInvitation_FieldMask) SubtractRaw(other gotenobject.FieldMask) gotenobject.FieldMask {
   157  	return fieldMask.Subtract(other.(*ProjectInvitation_FieldMask))
   158  }
   159  
   160  // FilterInputFields generates copy of field paths with output_only field paths removed
   161  func (fieldMask *ProjectInvitation_FieldMask) FilterInputFields() *ProjectInvitation_FieldMask {
   162  	result := &ProjectInvitation_FieldMask{}
   163  	for _, path := range fieldMask.Paths {
   164  		switch path.Selector() {
   165  		case ProjectInvitation_FieldPathSelectorProjectDisplayName:
   166  		case ProjectInvitation_FieldPathSelectorMetadata:
   167  			if _, ok := path.(*ProjectInvitation_FieldTerminalPath); ok {
   168  				for _, subpath := range meta.FullMeta_FieldMask().FilterInputFields().Paths {
   169  					result.Paths = append(result.Paths, &ProjectInvitation_FieldSubPath{selector: path.Selector(), subPath: subpath})
   170  				}
   171  			} else if sub, ok := path.(*ProjectInvitation_FieldSubPath); ok {
   172  				selectedMask := &meta.Meta_FieldMask{
   173  					Paths: []meta.Meta_FieldPath{sub.subPath.(meta.Meta_FieldPath)},
   174  				}
   175  				for _, allowedPath := range selectedMask.FilterInputFields().Paths {
   176  					result.Paths = append(result.Paths, &ProjectInvitation_FieldSubPath{selector: ProjectInvitation_FieldPathSelectorMetadata, subPath: allowedPath})
   177  				}
   178  			}
   179  		case ProjectInvitation_FieldPathSelectorInvitation:
   180  			if _, ok := path.(*ProjectInvitation_FieldTerminalPath); ok {
   181  				for _, subpath := range iam_invitation.FullInvitation_FieldMask().FilterInputFields().Paths {
   182  					result.Paths = append(result.Paths, &ProjectInvitation_FieldSubPath{selector: path.Selector(), subPath: subpath})
   183  				}
   184  			} else if sub, ok := path.(*ProjectInvitation_FieldSubPath); ok {
   185  				selectedMask := &iam_invitation.Invitation_FieldMask{
   186  					Paths: []iam_invitation.Invitation_FieldPath{sub.subPath.(iam_invitation.Invitation_FieldPath)},
   187  				}
   188  				for _, allowedPath := range selectedMask.FilterInputFields().Paths {
   189  					result.Paths = append(result.Paths, &ProjectInvitation_FieldSubPath{selector: ProjectInvitation_FieldPathSelectorInvitation, subPath: allowedPath})
   190  				}
   191  			}
   192  		default:
   193  			result.Paths = append(result.Paths, path)
   194  		}
   195  	}
   196  	return result
   197  }
   198  
   199  // ToFieldMask is used for proto conversions
   200  func (fieldMask *ProjectInvitation_FieldMask) ToProtoFieldMask() *googlefieldmaskpb.FieldMask {
   201  	protoFieldMask := &googlefieldmaskpb.FieldMask{}
   202  	for _, path := range fieldMask.Paths {
   203  		protoFieldMask.Paths = append(protoFieldMask.Paths, path.String())
   204  	}
   205  	return protoFieldMask
   206  }
   207  
   208  func (fieldMask *ProjectInvitation_FieldMask) FromProtoFieldMask(protoFieldMask *googlefieldmaskpb.FieldMask) error {
   209  	if fieldMask == nil {
   210  		return status.Error(codes.Internal, "target field mask is nil")
   211  	}
   212  	fieldMask.Paths = make([]ProjectInvitation_FieldPath, 0, len(protoFieldMask.Paths))
   213  	for _, strPath := range protoFieldMask.Paths {
   214  		path, err := ParseProjectInvitation_FieldPath(strPath)
   215  		if err != nil {
   216  			return err
   217  		}
   218  		fieldMask.Paths = append(fieldMask.Paths, path)
   219  	}
   220  	return nil
   221  }
   222  
   223  // implement methods required by customType
   224  func (fieldMask ProjectInvitation_FieldMask) Marshal() ([]byte, error) {
   225  	protoFieldMask := fieldMask.ToProtoFieldMask()
   226  	return proto.Marshal(protoFieldMask)
   227  }
   228  
   229  func (fieldMask *ProjectInvitation_FieldMask) Unmarshal(data []byte) error {
   230  	protoFieldMask := &googlefieldmaskpb.FieldMask{}
   231  	if err := proto.Unmarshal(data, protoFieldMask); err != nil {
   232  		return err
   233  	}
   234  	if err := fieldMask.FromProtoFieldMask(protoFieldMask); err != nil {
   235  		return err
   236  	}
   237  	return nil
   238  }
   239  
   240  func (fieldMask *ProjectInvitation_FieldMask) Size() int {
   241  	return proto.Size(fieldMask.ToProtoFieldMask())
   242  }
   243  
   244  func (fieldMask ProjectInvitation_FieldMask) MarshalJSON() ([]byte, error) {
   245  	return json.Marshal(fieldMask.ToProtoFieldMask())
   246  }
   247  
   248  func (fieldMask *ProjectInvitation_FieldMask) UnmarshalJSON(data []byte) error {
   249  	protoFieldMask := &googlefieldmaskpb.FieldMask{}
   250  	if err := json.Unmarshal(data, protoFieldMask); err != nil {
   251  		return err
   252  	}
   253  	if err := fieldMask.FromProtoFieldMask(protoFieldMask); err != nil {
   254  		return err
   255  	}
   256  	return nil
   257  }
   258  
   259  func (fieldMask *ProjectInvitation_FieldMask) AppendPath(path ProjectInvitation_FieldPath) {
   260  	fieldMask.Paths = append(fieldMask.Paths, path)
   261  }
   262  
   263  func (fieldMask *ProjectInvitation_FieldMask) AppendRawPath(path gotenobject.FieldPath) {
   264  	fieldMask.Paths = append(fieldMask.Paths, path.(ProjectInvitation_FieldPath))
   265  }
   266  
   267  func (fieldMask *ProjectInvitation_FieldMask) GetPaths() []ProjectInvitation_FieldPath {
   268  	if fieldMask == nil {
   269  		return nil
   270  	}
   271  	return fieldMask.Paths
   272  }
   273  
   274  func (fieldMask *ProjectInvitation_FieldMask) GetRawPaths() []gotenobject.FieldPath {
   275  	if fieldMask == nil {
   276  		return nil
   277  	}
   278  	rawPaths := make([]gotenobject.FieldPath, 0, len(fieldMask.Paths))
   279  	for _, path := range fieldMask.Paths {
   280  		rawPaths = append(rawPaths, path)
   281  	}
   282  	return rawPaths
   283  }
   284  
   285  func (fieldMask *ProjectInvitation_FieldMask) SetFromCliFlag(raw string) error {
   286  	path, err := ParseProjectInvitation_FieldPath(raw)
   287  	if err != nil {
   288  		return err
   289  	}
   290  	fieldMask.Paths = append(fieldMask.Paths, path)
   291  	return nil
   292  }
   293  
   294  func (fieldMask *ProjectInvitation_FieldMask) Set(target, source *ProjectInvitation) {
   295  	for _, path := range fieldMask.Paths {
   296  		val, _ := path.GetSingle(source)
   297  		// if val is nil, then field does not exist in source, skip
   298  		// otherwise, process (can still reflect.ValueOf(val).IsNil!)
   299  		if val != nil {
   300  			path.WithIValue(val).SetTo(&target)
   301  		}
   302  	}
   303  }
   304  
   305  func (fieldMask *ProjectInvitation_FieldMask) SetRaw(target, source gotenobject.GotenObjectExt) {
   306  	fieldMask.Set(target.(*ProjectInvitation), source.(*ProjectInvitation))
   307  }
   308  
   309  func (fieldMask *ProjectInvitation_FieldMask) Project(source *ProjectInvitation) *ProjectInvitation {
   310  	if source == nil {
   311  		return nil
   312  	}
   313  	if fieldMask == nil {
   314  		return source
   315  	}
   316  	result := &ProjectInvitation{}
   317  	metadataMask := &meta.Meta_FieldMask{}
   318  	wholeMetadataAccepted := false
   319  	invitationMask := &iam_invitation.Invitation_FieldMask{}
   320  	wholeInvitationAccepted := false
   321  
   322  	for _, p := range fieldMask.Paths {
   323  		switch tp := p.(type) {
   324  		case *ProjectInvitation_FieldTerminalPath:
   325  			switch tp.selector {
   326  			case ProjectInvitation_FieldPathSelectorName:
   327  				result.Name = source.Name
   328  			case ProjectInvitation_FieldPathSelectorMetadata:
   329  				result.Metadata = source.Metadata
   330  				wholeMetadataAccepted = true
   331  			case ProjectInvitation_FieldPathSelectorProjectDisplayName:
   332  				result.ProjectDisplayName = source.ProjectDisplayName
   333  			case ProjectInvitation_FieldPathSelectorInvitation:
   334  				result.Invitation = source.Invitation
   335  				wholeInvitationAccepted = true
   336  			}
   337  		case *ProjectInvitation_FieldSubPath:
   338  			switch tp.selector {
   339  			case ProjectInvitation_FieldPathSelectorMetadata:
   340  				metadataMask.AppendPath(tp.subPath.(meta.Meta_FieldPath))
   341  			case ProjectInvitation_FieldPathSelectorInvitation:
   342  				invitationMask.AppendPath(tp.subPath.(iam_invitation.Invitation_FieldPath))
   343  			}
   344  		}
   345  	}
   346  	if wholeMetadataAccepted == false && len(metadataMask.Paths) > 0 {
   347  		result.Metadata = metadataMask.Project(source.GetMetadata())
   348  	}
   349  	if wholeInvitationAccepted == false && len(invitationMask.Paths) > 0 {
   350  		result.Invitation = invitationMask.Project(source.GetInvitation())
   351  	}
   352  	return result
   353  }
   354  
   355  func (fieldMask *ProjectInvitation_FieldMask) ProjectRaw(source gotenobject.GotenObjectExt) gotenobject.GotenObjectExt {
   356  	return fieldMask.Project(source.(*ProjectInvitation))
   357  }
   358  
   359  func (fieldMask *ProjectInvitation_FieldMask) PathsCount() int {
   360  	if fieldMask == nil {
   361  		return 0
   362  	}
   363  	return len(fieldMask.Paths)
   364  }