Commit aed2b2a 1 parent 074a260 commit aed2b2a Copy full SHA for aed2b2a
File tree 2 files changed +10
-32
lines changed
2 files changed +10
-32
lines changed Original file line number Diff line number Diff line change @@ -231,35 +231,14 @@ extension _CBORDecoder.SingleValueContainer: SingleValueDecodingContainer {
231
231
}
232
232
}
233
233
234
- func decode( _ type: Data . Type ) throws -> Data {
235
- guard let cbor = try ? CBOR . decode ( self . data. map { $0 } ) else {
236
- let context = DecodingError . Context ( codingPath: self . codingPath, debugDescription: " Invalid format: \( self . data) " )
237
- throw DecodingError . dataCorrupted ( context)
238
- }
239
- switch cbor {
240
- case . byteString( let bytes) : return Data ( bytes)
241
- default :
242
- let context = DecodingError . Context ( codingPath: self . codingPath, debugDescription: " Invalid format: \( self . data) " )
243
- throw DecodingError . typeMismatch ( Data . self, context)
244
- }
245
- }
246
-
247
234
func decode< T: Decodable > ( _ type: T . Type ) throws -> T {
248
- switch type {
249
- // TODO: These seem unnecessary/wrong?!
250
- case is Data . Type :
251
- return try decode ( Data . self) as! T
252
- case is Date . Type :
253
- return try decode ( Date . self) as! T
254
- default :
255
- let decoder = _CBORDecoder ( data: self . data, options: self . options)
256
- let value = try T ( from: decoder)
257
- if let nextIndex = decoder. container? . index {
258
- self . index = nextIndex
259
- }
260
-
261
- return value
235
+ let decoder = _CBORDecoder ( data: self . data, options: self . options)
236
+ let value = try T ( from: decoder)
237
+ if let nextIndex = decoder. container? . index {
238
+ self . index = nextIndex
262
239
}
240
+
241
+ return value
263
242
}
264
243
}
265
244
Original file line number Diff line number Diff line change @@ -131,14 +131,14 @@ extension _CBOREncoder.SingleValueContainer: SingleValueEncodingContainer {
131
131
self . storage. append ( contentsOf: CBOR . encode ( value) )
132
132
}
133
133
134
- func encode ( _ value: Date ) throws {
134
+ func encodeDate ( _ value: Date ) throws {
135
135
try checkCanEncode ( value: value)
136
136
defer { self . canEncodeNewValue = false }
137
137
138
138
self . storage. append ( contentsOf: CBOR . encodeDate ( value, options: self . options. toCBOROptions ( ) ) )
139
139
}
140
140
141
- func encode ( _ value: Data ) throws {
141
+ func encodeData ( _ value: Data ) throws {
142
142
try checkCanEncode ( value: value)
143
143
defer { self . canEncodeNewValue = false }
144
144
@@ -151,15 +151,14 @@ extension _CBOREncoder.SingleValueContainer: SingleValueEncodingContainer {
151
151
152
152
switch value {
153
153
case let data as Data :
154
- try self . encode ( data)
154
+ try self . encodeData ( data)
155
155
case let date as Date :
156
- try self . encode ( date)
156
+ try self . encodeDate ( date)
157
157
default :
158
158
let encoder = _CBOREncoder ( options: self . options)
159
159
try value. encode ( to: encoder)
160
160
self . storage. append ( encoder. data)
161
161
}
162
-
163
162
}
164
163
}
165
164
You can’t perform that action at this time.
0 commit comments