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