mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Temp
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import Foundation
|
||||
|
||||
final public class AdaptedPostboxDecoder {
|
||||
func decode<T>(_ type: T.Type, from data: Data) throws -> T where T : Decodable {
|
||||
let decoder = _AdaptedPostboxDecoder(data: data)
|
||||
return try T(from: decoder)
|
||||
}
|
||||
}
|
||||
|
||||
final class _AdaptedPostboxDecoder {
|
||||
var codingPath: [CodingKey] = []
|
||||
|
||||
var userInfo: [CodingUserInfoKey : Any] = [:]
|
||||
|
||||
var container: AdaptedPostboxDecodingContainer?
|
||||
fileprivate var data: Data
|
||||
|
||||
init(data: Data) {
|
||||
self.data = data
|
||||
}
|
||||
}
|
||||
|
||||
extension _AdaptedPostboxDecoder: Decoder {
|
||||
fileprivate func assertCanCreateContainer() {
|
||||
precondition(self.container == nil)
|
||||
}
|
||||
|
||||
func container<Key>(keyedBy type: Key.Type) -> KeyedDecodingContainer<Key> where Key : CodingKey {
|
||||
assertCanCreateContainer()
|
||||
|
||||
let container = KeyedContainer<Key>(data: self.data, codingPath: self.codingPath, userInfo: self.userInfo)
|
||||
self.container = container
|
||||
|
||||
return KeyedDecodingContainer(container)
|
||||
}
|
||||
|
||||
func unkeyedContainer() -> UnkeyedDecodingContainer {
|
||||
preconditionFailure()
|
||||
}
|
||||
|
||||
func singleValueContainer() -> SingleValueDecodingContainer {
|
||||
preconditionFailure()
|
||||
}
|
||||
}
|
||||
|
||||
protocol AdaptedPostboxDecodingContainer: AnyObject {
|
||||
}
|
||||
Reference in New Issue
Block a user