File tree Expand file tree Collapse file tree 3 files changed +122
-63
lines changed Expand file tree Collapse file tree 3 files changed +122
-63
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,10 @@ extension Message {
34
34
}
35
35
}
36
36
37
+ public enum MergeOption : Equatable {
38
+ case replaceRepeatedFields
39
+ }
40
+
37
41
extension Message {
38
42
39
43
/// Merges fields specified in a FieldMask into another message.
@@ -43,16 +47,23 @@ extension Message {
43
47
/// - fieldMask: FieldMask specifies which fields should be merged.
44
48
public mutating func merge(
45
49
to source: Self ,
46
- fieldMask: Google_Protobuf_FieldMask
50
+ fieldMask: Google_Protobuf_FieldMask ,
51
+ mergeOptions: [ MergeOption ] = [ ]
47
52
) throws {
48
53
var source = source
49
54
var copy = self
50
55
var pathToValueMap : [ String : Any ? ] = [ : ]
56
+ let replaceRepeatedFields = mergeOptions
57
+ . contains ( . replaceRepeatedFields)
51
58
for path in fieldMask. paths {
52
59
pathToValueMap [ path] = try source. get ( path: path)
53
60
}
54
61
for (path, value) in pathToValueMap {
55
- try copy. set ( path: path, value: value)
62
+ try copy. set (
63
+ path: path,
64
+ value: value,
65
+ replaceRepeatedFields: replaceRepeatedFields
66
+ )
56
67
}
57
68
self = copy
58
69
}
You can’t perform that action at this time.
0 commit comments