-
Notifications
You must be signed in to change notification settings - Fork 1
/
group_member.pb.fieldmask.go
367 lines (326 loc) · 11.3 KB
/
group_member.pb.fieldmask.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
// Code generated by protoc-gen-goten-object
// File: edgelq/iam/proto/v1alpha2/group_member.proto
// DO NOT EDIT!!!
package group_member
import (
"encoding/json"
"strings"
firestorepb "google.golang.org/genproto/googleapis/firestore/v1"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
preflect "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/types/known/fieldmaskpb"
gotenobject "github.com/cloudwan/goten-sdk/runtime/object"
)
// proto imports
import (
ntt_meta "github.com/cloudwan/edgelq-sdk/common/types/meta"
group "github.com/cloudwan/edgelq-sdk/iam/resources/v1alpha2/group"
)
// ensure the imports are used
var (
_ = json.Marshaler(nil)
_ = strings.Builder{}
_ = firestorepb.Value{}
_ = codes.NotFound
_ = status.Status{}
_ = proto.Message(nil)
_ = preflect.Message(nil)
_ = fieldmaskpb.FieldMask{}
_ = gotenobject.FieldMask(nil)
)
// make sure we're using proto imports
var (
_ = &ntt_meta.Meta{}
_ = &group.Group{}
)
type GroupMember_FieldMask struct {
Paths []GroupMember_FieldPath
}
func FullGroupMember_FieldMask() *GroupMember_FieldMask {
res := &GroupMember_FieldMask{}
res.Paths = append(res.Paths, &GroupMember_FieldTerminalPath{selector: GroupMember_FieldPathSelectorName})
res.Paths = append(res.Paths, &GroupMember_FieldTerminalPath{selector: GroupMember_FieldPathSelectorMember})
res.Paths = append(res.Paths, &GroupMember_FieldTerminalPath{selector: GroupMember_FieldPathSelectorParentMember})
res.Paths = append(res.Paths, &GroupMember_FieldTerminalPath{selector: GroupMember_FieldPathSelectorMinAncestryMembers})
res.Paths = append(res.Paths, &GroupMember_FieldTerminalPath{selector: GroupMember_FieldPathSelectorMetadata})
return res
}
func (fieldMask *GroupMember_FieldMask) String() string {
if fieldMask == nil {
return "<nil>"
}
pathsStr := make([]string, 0, len(fieldMask.Paths))
for _, path := range fieldMask.Paths {
pathsStr = append(pathsStr, path.String())
}
return strings.Join(pathsStr, ", ")
}
// firestore encoding/decoding integration
func (fieldMask *GroupMember_FieldMask) EncodeFirestore() (*firestorepb.Value, error) {
if fieldMask == nil {
return &firestorepb.Value{ValueType: &firestorepb.Value_NullValue{}}, nil
}
arrayValues := make([]*firestorepb.Value, 0, len(fieldMask.Paths))
for _, path := range fieldMask.GetPaths() {
arrayValues = append(arrayValues, &firestorepb.Value{ValueType: &firestorepb.Value_StringValue{StringValue: path.String()}})
}
return &firestorepb.Value{
ValueType: &firestorepb.Value_ArrayValue{ArrayValue: &firestorepb.ArrayValue{Values: arrayValues}},
}, nil
}
func (fieldMask *GroupMember_FieldMask) DecodeFirestore(fpbv *firestorepb.Value) error {
for _, value := range fpbv.GetArrayValue().GetValues() {
parsedPath, err := ParseGroupMember_FieldPath(value.GetStringValue())
if err != nil {
return err
}
fieldMask.Paths = append(fieldMask.Paths, parsedPath)
}
return nil
}
func (fieldMask *GroupMember_FieldMask) IsFull() bool {
if fieldMask == nil {
return false
}
presentSelectors := make([]bool, 5)
for _, path := range fieldMask.Paths {
if asFinal, ok := path.(*GroupMember_FieldTerminalPath); ok {
presentSelectors[int(asFinal.selector)] = true
}
}
for _, flag := range presentSelectors {
if !flag {
return false
}
}
return true
}
func (fieldMask *GroupMember_FieldMask) ProtoReflect() preflect.Message {
return gotenobject.MakeFieldMaskReflection(fieldMask, func(raw string) (gotenobject.FieldPath, error) {
return ParseGroupMember_FieldPath(raw)
})
}
func (fieldMask *GroupMember_FieldMask) ProtoMessage() {}
func (fieldMask *GroupMember_FieldMask) Reset() {
if fieldMask != nil {
fieldMask.Paths = nil
}
}
func (fieldMask *GroupMember_FieldMask) Subtract(other *GroupMember_FieldMask) *GroupMember_FieldMask {
result := &GroupMember_FieldMask{}
removedSelectors := make([]bool, 5)
otherSubMasks := map[GroupMember_FieldPathSelector]gotenobject.FieldMask{
GroupMember_FieldPathSelectorMetadata: &ntt_meta.Meta_FieldMask{},
}
mySubMasks := map[GroupMember_FieldPathSelector]gotenobject.FieldMask{
GroupMember_FieldPathSelectorMetadata: &ntt_meta.Meta_FieldMask{},
}
for _, path := range other.GetPaths() {
switch tp := path.(type) {
case *GroupMember_FieldTerminalPath:
removedSelectors[int(tp.selector)] = true
case *GroupMember_FieldSubPath:
otherSubMasks[tp.selector].AppendRawPath(tp.subPath)
}
}
for _, path := range fieldMask.GetPaths() {
if !removedSelectors[int(path.Selector())] {
if otherSubMask := otherSubMasks[path.Selector()]; otherSubMask != nil && otherSubMask.PathsCount() > 0 {
if tp, ok := path.(*GroupMember_FieldTerminalPath); ok {
switch tp.selector {
case GroupMember_FieldPathSelectorMetadata:
mySubMasks[GroupMember_FieldPathSelectorMetadata] = ntt_meta.FullMeta_FieldMask()
}
} else if tp, ok := path.(*GroupMember_FieldSubPath); ok {
mySubMasks[tp.selector].AppendRawPath(tp.subPath)
}
} else {
result.Paths = append(result.Paths, path)
}
}
}
for selector, mySubMask := range mySubMasks {
if mySubMask.PathsCount() > 0 {
for _, allowedPath := range mySubMask.SubtractRaw(otherSubMasks[selector]).GetRawPaths() {
result.Paths = append(result.Paths, &GroupMember_FieldSubPath{selector: selector, subPath: allowedPath})
}
}
}
if len(result.Paths) == 0 {
return nil
}
return result
}
func (fieldMask *GroupMember_FieldMask) SubtractRaw(other gotenobject.FieldMask) gotenobject.FieldMask {
return fieldMask.Subtract(other.(*GroupMember_FieldMask))
}
// FilterInputFields generates copy of field paths with output_only field paths removed
func (fieldMask *GroupMember_FieldMask) FilterInputFields() *GroupMember_FieldMask {
result := &GroupMember_FieldMask{}
for _, path := range fieldMask.Paths {
switch path.Selector() {
case GroupMember_FieldPathSelectorParentMember:
case GroupMember_FieldPathSelectorMetadata:
if _, ok := path.(*GroupMember_FieldTerminalPath); ok {
for _, subpath := range ntt_meta.FullMeta_FieldMask().FilterInputFields().Paths {
result.Paths = append(result.Paths, &GroupMember_FieldSubPath{selector: path.Selector(), subPath: subpath})
}
} else if sub, ok := path.(*GroupMember_FieldSubPath); ok {
selectedMask := &ntt_meta.Meta_FieldMask{
Paths: []ntt_meta.Meta_FieldPath{sub.subPath.(ntt_meta.Meta_FieldPath)},
}
for _, allowedPath := range selectedMask.FilterInputFields().Paths {
result.Paths = append(result.Paths, &GroupMember_FieldSubPath{selector: GroupMember_FieldPathSelectorMetadata, subPath: allowedPath})
}
}
default:
result.Paths = append(result.Paths, path)
}
}
return result
}
// ToFieldMask is used for proto conversions
func (fieldMask *GroupMember_FieldMask) ToProtoFieldMask() *fieldmaskpb.FieldMask {
protoFieldMask := &fieldmaskpb.FieldMask{}
for _, path := range fieldMask.Paths {
protoFieldMask.Paths = append(protoFieldMask.Paths, path.String())
}
return protoFieldMask
}
func (fieldMask *GroupMember_FieldMask) FromProtoFieldMask(protoFieldMask *fieldmaskpb.FieldMask) error {
if fieldMask == nil {
return status.Error(codes.Internal, "target field mask is nil")
}
fieldMask.Paths = make([]GroupMember_FieldPath, 0, len(protoFieldMask.Paths))
for _, strPath := range protoFieldMask.Paths {
path, err := ParseGroupMember_FieldPath(strPath)
if err != nil {
return err
}
fieldMask.Paths = append(fieldMask.Paths, path)
}
return nil
}
// implement methods required by customType
func (fieldMask GroupMember_FieldMask) Marshal() ([]byte, error) {
protoFieldMask := fieldMask.ToProtoFieldMask()
return proto.Marshal(protoFieldMask)
}
func (fieldMask *GroupMember_FieldMask) Unmarshal(data []byte) error {
protoFieldMask := &fieldmaskpb.FieldMask{}
if err := proto.Unmarshal(data, protoFieldMask); err != nil {
return err
}
if err := fieldMask.FromProtoFieldMask(protoFieldMask); err != nil {
return err
}
return nil
}
func (fieldMask *GroupMember_FieldMask) Size() int {
return proto.Size(fieldMask.ToProtoFieldMask())
}
func (fieldMask GroupMember_FieldMask) MarshalJSON() ([]byte, error) {
return json.Marshal(fieldMask.ToProtoFieldMask())
}
func (fieldMask *GroupMember_FieldMask) UnmarshalJSON(data []byte) error {
protoFieldMask := &fieldmaskpb.FieldMask{}
if err := json.Unmarshal(data, protoFieldMask); err != nil {
return err
}
if err := fieldMask.FromProtoFieldMask(protoFieldMask); err != nil {
return err
}
return nil
}
func (fieldMask *GroupMember_FieldMask) AppendPath(path GroupMember_FieldPath) {
fieldMask.Paths = append(fieldMask.Paths, path)
}
func (fieldMask *GroupMember_FieldMask) AppendRawPath(path gotenobject.FieldPath) {
fieldMask.Paths = append(fieldMask.Paths, path.(GroupMember_FieldPath))
}
func (fieldMask *GroupMember_FieldMask) GetPaths() []GroupMember_FieldPath {
if fieldMask == nil {
return nil
}
return fieldMask.Paths
}
func (fieldMask *GroupMember_FieldMask) GetRawPaths() []gotenobject.FieldPath {
if fieldMask == nil {
return nil
}
rawPaths := make([]gotenobject.FieldPath, 0, len(fieldMask.Paths))
for _, path := range fieldMask.Paths {
rawPaths = append(rawPaths, path)
}
return rawPaths
}
func (fieldMask *GroupMember_FieldMask) SetFromCliFlag(raw string) error {
path, err := ParseGroupMember_FieldPath(raw)
if err != nil {
return err
}
fieldMask.Paths = append(fieldMask.Paths, path)
return nil
}
func (fieldMask *GroupMember_FieldMask) Set(target, source *GroupMember) {
for _, path := range fieldMask.Paths {
val, _ := path.GetSingle(source)
// if val is nil, then field does not exist in source, skip
// otherwise, process (can still reflect.ValueOf(val).IsNil!)
if val != nil {
path.WithIValue(val).SetTo(&target)
}
}
}
func (fieldMask *GroupMember_FieldMask) SetRaw(target, source gotenobject.GotenObjectExt) {
fieldMask.Set(target.(*GroupMember), source.(*GroupMember))
}
func (fieldMask *GroupMember_FieldMask) Project(source *GroupMember) *GroupMember {
if source == nil {
return nil
}
if fieldMask == nil {
return source
}
result := &GroupMember{}
metadataMask := &ntt_meta.Meta_FieldMask{}
wholeMetadataAccepted := false
for _, p := range fieldMask.Paths {
switch tp := p.(type) {
case *GroupMember_FieldTerminalPath:
switch tp.selector {
case GroupMember_FieldPathSelectorName:
result.Name = source.Name
case GroupMember_FieldPathSelectorMember:
result.Member = source.Member
case GroupMember_FieldPathSelectorParentMember:
result.ParentMember = source.ParentMember
case GroupMember_FieldPathSelectorMinAncestryMembers:
result.MinAncestryMembers = source.MinAncestryMembers
case GroupMember_FieldPathSelectorMetadata:
result.Metadata = source.Metadata
wholeMetadataAccepted = true
}
case *GroupMember_FieldSubPath:
switch tp.selector {
case GroupMember_FieldPathSelectorMetadata:
metadataMask.AppendPath(tp.subPath.(ntt_meta.Meta_FieldPath))
}
}
}
if wholeMetadataAccepted == false && len(metadataMask.Paths) > 0 {
result.Metadata = metadataMask.Project(source.GetMetadata())
}
return result
}
func (fieldMask *GroupMember_FieldMask) ProjectRaw(source gotenobject.GotenObjectExt) gotenobject.GotenObjectExt {
return fieldMask.Project(source.(*GroupMember))
}
func (fieldMask *GroupMember_FieldMask) PathsCount() int {
if fieldMask == nil {
return 0
}
return len(fieldMask.Paths)
}