Refactoring

This commit is contained in:
Ali
2021-08-12 16:41:11 +02:00
parent adc430b870
commit bf253eec46
84 changed files with 604 additions and 443 deletions

View File

@@ -10,6 +10,16 @@ final public class AdaptedPostboxDecoder {
case dataArray
}
public final class RawObjectData: Codable {
public let data: Data
public let typeHash: Int32
public init(data: Data, typeHash: Int32) {
self.data = data
self.typeHash = typeHash
}
}
public init() {
}
@@ -24,7 +34,7 @@ final public class AdaptedPostboxDecoder {
}
extension AdaptedPostboxDecoder.ContentType {
init?(valueType: ValueType) {
init?(valueType: ObjectDataValueType) {
switch valueType {
case .Int32:
return nil

View File

@@ -35,6 +35,14 @@ extension _AdaptedPostboxDecoder.KeyedContainer: KeyedDecodingContainerProtocol
func decode<T>(_ type: T.Type, forKey key: Key) throws -> T where T : Decodable {
if let (data, valueType) = self.decoder.decodeObjectDataForKey(key.stringValue) {
if type == AdaptedPostboxDecoder.RawObjectData.self {
if case let .Object(typeHash) = valueType {
return AdaptedPostboxDecoder.RawObjectData(data: data, typeHash: typeHash) as! T
} else {
decodingErrorBreakpoint()
throw DecodingError.typeMismatch(T.self, DecodingError.Context(codingPath: self.codingPath + [key], debugDescription: ""))
}
}
if let mappedType = AdaptedPostboxDecoder.ContentType(valueType: valueType) {
return try AdaptedPostboxDecoder().decode(T.self, from: data, contentType: mappedType)
} else {