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