@@ -30,10 +30,12 @@ struct GetPathDecoder<T: Message>: Decoder {
30
30
_hasPath
31
31
}
32
32
33
- internal init ( path: [ String ] ) {
34
- if let firstComponent = path. first {
35
- self . number = T . number ( for: firstComponent)
33
+ internal init ( path: [ String ] ) throws {
34
+ guard let firstComponent = path. first,
35
+ let number = T . number ( for: firstComponent) else {
36
+ throw PathDecodingError . pathNotFound
36
37
}
38
+ self . number = number
37
39
self . nextPath = . init( path. dropFirst ( ) )
38
40
}
39
41
@@ -44,211 +46,214 @@ struct GetPathDecoder<T: Message>: Decoder {
44
46
return number
45
47
}
46
48
47
- private mutating func captureValue( _ value: Any ? ) {
49
+ private mutating func captureValue( _ value: Any ? ) throws {
50
+ if !nextPath. isEmpty {
51
+ throw PathDecodingError . pathNotFound
52
+ }
48
53
self . _value = value
49
54
self . _hasPath = true
50
55
}
51
56
52
57
mutating func decodeSingularFloatField( value: inout Float ) throws {
53
- captureValue ( value)
58
+ try captureValue ( value)
54
59
}
55
60
56
61
mutating func decodeSingularFloatField( value: inout Float ? ) throws {
57
- captureValue ( value)
62
+ try captureValue ( value)
58
63
}
59
64
60
65
mutating func decodeRepeatedFloatField( value: inout [ Float ] ) throws {
61
- captureValue ( value)
66
+ try captureValue ( value)
62
67
}
63
68
64
69
mutating func decodeSingularDoubleField( value: inout Double ) throws {
65
- captureValue ( value)
70
+ try captureValue ( value)
66
71
}
67
72
68
73
mutating func decodeSingularDoubleField( value: inout Double ? ) throws {
69
- captureValue ( value)
74
+ try captureValue ( value)
70
75
}
71
76
72
77
mutating func decodeRepeatedDoubleField( value: inout [ Double ] ) throws {
73
- captureValue ( value)
78
+ try captureValue ( value)
74
79
}
75
80
76
81
mutating func decodeSingularInt32Field( value: inout Int32 ) throws {
77
- captureValue ( value)
82
+ try captureValue ( value)
78
83
}
79
84
80
85
mutating func decodeSingularInt32Field( value: inout Int32 ? ) throws {
81
- captureValue ( value)
86
+ try captureValue ( value)
82
87
}
83
88
84
89
mutating func decodeRepeatedInt32Field( value: inout [ Int32 ] ) throws {
85
- captureValue ( value)
90
+ try captureValue ( value)
86
91
}
87
92
88
93
mutating func decodeSingularInt64Field( value: inout Int64 ) throws {
89
- captureValue ( value)
94
+ try captureValue ( value)
90
95
}
91
96
92
97
mutating func decodeSingularInt64Field( value: inout Int64 ? ) throws {
93
- captureValue ( value)
98
+ try captureValue ( value)
94
99
}
95
100
96
101
mutating func decodeRepeatedInt64Field( value: inout [ Int64 ] ) throws {
97
- captureValue ( value)
102
+ try captureValue ( value)
98
103
}
99
104
100
105
mutating func decodeSingularUInt32Field( value: inout UInt32 ) throws {
101
- captureValue ( value)
106
+ try captureValue ( value)
102
107
}
103
108
104
109
mutating func decodeSingularUInt32Field( value: inout UInt32 ? ) throws {
105
- captureValue ( value)
110
+ try captureValue ( value)
106
111
}
107
112
108
113
mutating func decodeRepeatedUInt32Field( value: inout [ UInt32 ] ) throws {
109
- captureValue ( value)
114
+ try captureValue ( value)
110
115
}
111
116
112
117
mutating func decodeSingularUInt64Field( value: inout UInt64 ) throws {
113
- captureValue ( value)
118
+ try captureValue ( value)
114
119
}
115
120
116
121
mutating func decodeSingularUInt64Field( value: inout UInt64 ? ) throws {
117
- captureValue ( value)
122
+ try captureValue ( value)
118
123
}
119
124
120
125
mutating func decodeRepeatedUInt64Field( value: inout [ UInt64 ] ) throws {
121
- captureValue ( value)
126
+ try captureValue ( value)
122
127
}
123
128
124
129
mutating func decodeSingularSInt32Field( value: inout Int32 ) throws {
125
- captureValue ( value)
130
+ try captureValue ( value)
126
131
}
127
132
128
133
mutating func decodeSingularSInt32Field( value: inout Int32 ? ) throws {
129
- captureValue ( value)
134
+ try captureValue ( value)
130
135
}
131
136
132
137
mutating func decodeRepeatedSInt32Field( value: inout [ Int32 ] ) throws {
133
- captureValue ( value)
138
+ try captureValue ( value)
134
139
}
135
140
136
141
mutating func decodeSingularSInt64Field( value: inout Int64 ) throws {
137
- captureValue ( value)
142
+ try captureValue ( value)
138
143
}
139
144
140
145
mutating func decodeSingularSInt64Field( value: inout Int64 ? ) throws {
141
- captureValue ( value)
146
+ try captureValue ( value)
142
147
}
143
148
144
149
mutating func decodeRepeatedSInt64Field( value: inout [ Int64 ] ) throws {
145
- captureValue ( value)
150
+ try captureValue ( value)
146
151
}
147
152
148
153
mutating func decodeSingularFixed32Field( value: inout UInt32 ) throws {
149
- captureValue ( value)
154
+ try captureValue ( value)
150
155
}
151
156
152
157
mutating func decodeSingularFixed32Field( value: inout UInt32 ? ) throws {
153
- captureValue ( value)
158
+ try captureValue ( value)
154
159
}
155
160
156
161
mutating func decodeRepeatedFixed32Field( value: inout [ UInt32 ] ) throws {
157
- captureValue ( value)
162
+ try captureValue ( value)
158
163
}
159
164
160
165
mutating func decodeSingularFixed64Field( value: inout UInt64 ) throws {
161
- captureValue ( value)
166
+ try captureValue ( value)
162
167
}
163
168
164
169
mutating func decodeSingularFixed64Field( value: inout UInt64 ? ) throws {
165
- captureValue ( value)
170
+ try captureValue ( value)
166
171
}
167
172
168
173
mutating func decodeRepeatedFixed64Field( value: inout [ UInt64 ] ) throws {
169
- captureValue ( value)
174
+ try captureValue ( value)
170
175
}
171
176
172
177
mutating func decodeSingularSFixed32Field( value: inout Int32 ) throws {
173
- captureValue ( value)
178
+ try captureValue ( value)
174
179
}
175
180
176
181
mutating func decodeSingularSFixed32Field( value: inout Int32 ? ) throws {
177
- captureValue ( value)
182
+ try captureValue ( value)
178
183
}
179
184
180
185
mutating func decodeRepeatedSFixed32Field( value: inout [ Int32 ] ) throws {
181
- captureValue ( value)
186
+ try captureValue ( value)
182
187
}
183
188
184
189
mutating func decodeSingularSFixed64Field( value: inout Int64 ) throws {
185
- captureValue ( value)
190
+ try captureValue ( value)
186
191
}
187
192
188
193
mutating func decodeSingularSFixed64Field( value: inout Int64 ? ) throws {
189
- captureValue ( value)
194
+ try captureValue ( value)
190
195
}
191
196
192
197
mutating func decodeRepeatedSFixed64Field( value: inout [ Int64 ] ) throws {
193
- captureValue ( value)
198
+ try captureValue ( value)
194
199
}
195
200
196
201
mutating func decodeSingularBoolField( value: inout Bool ) throws {
197
- captureValue ( value)
202
+ try captureValue ( value)
198
203
}
199
204
200
205
mutating func decodeSingularBoolField( value: inout Bool ? ) throws {
201
- captureValue ( value)
206
+ try captureValue ( value)
202
207
}
203
208
204
209
mutating func decodeRepeatedBoolField( value: inout [ Bool ] ) throws {
205
- captureValue ( value)
210
+ try captureValue ( value)
206
211
}
207
212
208
213
mutating func decodeSingularStringField( value: inout String ) throws {
209
- captureValue ( value)
214
+ try captureValue ( value)
210
215
}
211
216
212
217
mutating func decodeSingularStringField( value: inout String ? ) throws {
213
- captureValue ( value)
218
+ try captureValue ( value)
214
219
}
215
220
216
221
mutating func decodeRepeatedStringField( value: inout [ String ] ) throws {
217
- captureValue ( value)
222
+ try captureValue ( value)
218
223
}
219
224
220
225
mutating func decodeSingularBytesField( value: inout Data ) throws {
221
- captureValue ( value)
226
+ try captureValue ( value)
222
227
}
223
228
224
229
mutating func decodeSingularBytesField( value: inout Data ? ) throws {
225
- captureValue ( value)
230
+ try captureValue ( value)
226
231
}
227
232
228
233
mutating func decodeRepeatedBytesField( value: inout [ Data ] ) throws {
229
- captureValue ( value)
234
+ try captureValue ( value)
230
235
}
231
236
232
237
mutating func decodeSingularEnumField< E> ( value: inout E ) throws {
233
- captureValue ( value)
238
+ try captureValue ( value)
234
239
}
235
240
236
241
mutating func decodeSingularEnumField< E> ( value: inout E ? ) throws {
237
- captureValue ( value)
242
+ try captureValue ( value)
238
243
}
239
244
240
245
mutating func decodeRepeatedEnumField< E> ( value: inout [ E ] ) throws {
241
- captureValue ( value)
246
+ try captureValue ( value)
242
247
}
243
248
244
249
mutating func decodeSingularMessageField< M> (
245
250
value: inout M ?
246
251
) throws where M : Message {
247
252
if nextPath. isEmpty {
248
- captureValue ( value)
253
+ try captureValue ( value)
249
254
return
250
255
}
251
- var decoder = GetPathDecoder < M > ( path: nextPath)
256
+ var decoder = try GetPathDecoder < M > ( path: nextPath)
252
257
if value != nil {
253
258
try value? . decodeMessage ( decoder: & decoder)
254
259
} else {
@@ -260,36 +265,36 @@ struct GetPathDecoder<T: Message>: Decoder {
260
265
}
261
266
262
267
mutating func decodeRepeatedMessageField< M> ( value: inout [ M ] ) throws {
263
- captureValue ( value)
268
+ try captureValue ( value)
264
269
}
265
270
266
271
mutating func decodeSingularGroupField< G> ( value: inout G ? ) throws {
267
- captureValue ( value)
272
+ try captureValue ( value)
268
273
}
269
274
270
275
mutating func decodeRepeatedGroupField< G> ( value: inout [ G ] ) throws {
271
- captureValue ( value)
276
+ try captureValue ( value)
272
277
}
273
278
274
279
mutating func decodeMapField< KeyType, ValueType> (
275
280
fieldType: _ProtobufMap < KeyType , ValueType > . Type ,
276
281
value: inout _ProtobufMap < KeyType , ValueType > . BaseType
277
282
) throws {
278
- captureValue ( value)
283
+ try captureValue ( value)
279
284
}
280
285
281
286
mutating func decodeMapField< KeyType, ValueType> (
282
287
fieldType: _ProtobufEnumMap < KeyType , ValueType > . Type ,
283
288
value: inout _ProtobufEnumMap < KeyType , ValueType > . BaseType
284
289
) throws {
285
- captureValue ( value)
290
+ try captureValue ( value)
286
291
}
287
292
288
293
mutating func decodeMapField< KeyType, ValueType> (
289
294
fieldType: _ProtobufMessageMap < KeyType , ValueType > . Type ,
290
295
value: inout _ProtobufMessageMap < KeyType , ValueType > . BaseType
291
296
) throws {
292
- captureValue ( value)
297
+ try captureValue ( value)
293
298
}
294
299
295
300
mutating func decodeExtensionField(
@@ -303,14 +308,16 @@ struct GetPathDecoder<T: Message>: Decoder {
303
308
extension Message {
304
309
mutating func `get`( path: String ) throws -> Any ? {
305
310
let _path = path. components ( separatedBy: " . " )
306
- var decoder = GetPathDecoder < Self > ( path: _path)
311
+ var decoder = try GetPathDecoder < Self > ( path: _path)
307
312
try decodeMessage ( decoder: & decoder)
308
313
return decoder. value
309
314
}
310
315
311
316
mutating func hasPath( path: String ) -> Bool {
312
317
let _path = path. components ( separatedBy: " . " )
313
- var decoder = GetPathDecoder < Self > ( path: _path)
318
+ guard var decoder = try ? GetPathDecoder < Self > ( path: _path) else {
319
+ return false
320
+ }
314
321
try ? decodeMessage ( decoder: & decoder)
315
322
return decoder. hasPath
316
323
}
0 commit comments