mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Refactoring
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user