Refactoring

This commit is contained in:
Ali
2021-08-03 12:23:13 +02:00
parent 1a0dc56953
commit 7e6eb2b3bd
46 changed files with 702 additions and 470 deletions

View File

@@ -38,8 +38,22 @@ extension _AdaptedPostboxDecoder.KeyedContainer: KeyedDecodingContainerProtocol
if let mappedType = AdaptedPostboxDecoder.ContentType(valueType: valueType) {
return try AdaptedPostboxDecoder().decode(T.self, from: data, contentType: mappedType)
} else {
decodingErrorBreakpoint()
throw DecodingError.typeMismatch(T.self, DecodingError.Context(codingPath: self.codingPath + [key], debugDescription: ""))
switch valueType {
case .Bytes:
guard let resultData = PostboxDecoder.parseDataRaw(data: data) else {
decodingErrorBreakpoint()
throw DecodingError.typeMismatch(T.self, DecodingError.Context(codingPath: self.codingPath + [key], debugDescription: ""))
}
if let resultData = resultData as? T {
return resultData
} else {
decodingErrorBreakpoint()
throw DecodingError.typeMismatch(T.self, DecodingError.Context(codingPath: self.codingPath + [key], debugDescription: ""))
}
default:
decodingErrorBreakpoint()
throw DecodingError.typeMismatch(T.self, DecodingError.Context(codingPath: self.codingPath + [key], debugDescription: ""))
}
}
} else {
decodingErrorBreakpoint()
@@ -82,6 +96,15 @@ extension _AdaptedPostboxDecoder.KeyedContainer: KeyedDecodingContainerProtocol
throw DecodingError.keyNotFound(key, DecodingError.Context(codingPath: self.codingPath + [key], debugDescription: ""))
}
}
func decode(_ type: Double.Type, forKey key: Key) throws -> Double {
if let value = self.decoder.decodeOptionalDoubleForKey(key.stringValue) {
return value
} else {
decodingErrorBreakpoint()
throw DecodingError.keyNotFound(key, DecodingError.Context(codingPath: self.codingPath + [key], debugDescription: ""))
}
}
func nestedUnkeyedContainer(forKey key: Key) throws -> UnkeyedDecodingContainer {
preconditionFailure()