@@ -21,7 +21,7 @@ enum AttributeValue: Codable, Equatable, CustomStringConvertible {
21
21
case int( Int64 ) // supported value range [-2^53, 2^53]
22
22
case double( Double )
23
23
case bool( Bool )
24
- // not defined in datafile schema, but required for forward compatiblity (see Nikhil's doc )
24
+ case custom ( [ String : AttributeValue ] )
25
25
case others
26
26
27
27
var description : String {
@@ -34,6 +34,8 @@ enum AttributeValue: Codable, Equatable, CustomStringConvertible {
34
34
return " int( \( value) ) "
35
35
case . bool( let value) :
36
36
return " bool( \( value) ) "
37
+ case . custom( let value) :
38
+ return " custom( \( value) ) "
37
39
case . others:
38
40
return " others "
39
41
}
@@ -63,6 +65,12 @@ enum AttributeValue: Codable, Equatable, CustomStringConvertible {
63
65
self = . bool( boolValue)
64
66
return
65
67
}
68
+
69
+ if let custom = value as? [ String : Any ] {
70
+ let attr = custom. compactMapValues { AttributeValue ( value: $0) }
71
+ self = . custom( attr)
72
+ return
73
+ }
66
74
67
75
return nil
68
76
}
@@ -87,6 +95,12 @@ enum AttributeValue: Codable, Equatable, CustomStringConvertible {
87
95
return
88
96
}
89
97
98
+ if let value = try ? container. decode ( [ String : AttributeValue ] . self) {
99
+ self = . custom( value)
100
+ return
101
+ }
102
+
103
+
90
104
// accept all other types (null, {}, []) for forward compatibility support
91
105
self = . others
92
106
}
@@ -103,6 +117,8 @@ enum AttributeValue: Codable, Equatable, CustomStringConvertible {
103
117
try container. encode ( value)
104
118
case . bool( let value) :
105
119
try container. encode ( value)
120
+ case . custom( let value) :
121
+ try container. encode ( value. mapValues { $0 } )
106
122
case . others:
107
123
return
108
124
}
@@ -135,6 +151,10 @@ extension AttributeValue {
135
151
return true
136
152
}
137
153
154
+ if case . custom( let selfDict) = self , case . custom( let targetDict) = targetValue {
155
+ return selfDict == targetDict
156
+ }
157
+
138
158
return false
139
159
}
140
160
@@ -227,6 +247,8 @@ extension AttributeValue {
227
247
return String ( value)
228
248
case . bool( let value) :
229
249
return String ( value)
250
+ case . custom( let value) :
251
+ return String ( describing: value)
230
252
case . others:
231
253
return " UNKNOWN "
232
254
}
@@ -240,6 +262,7 @@ extension AttributeValue {
240
262
case ( . double, . int) : return true
241
263
case ( . double, . double) : return true
242
264
case ( . bool, . bool) : return true
265
+ case ( . custom, . custom) : return true
243
266
default : return false
244
267
}
245
268
}
0 commit comments