mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Refactor SyncCore
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import Postbox
|
||||
|
||||
public struct SecureIdConfiguration: PostboxCoding {
|
||||
public let nativeLanguageByCountry: [String: String]
|
||||
|
||||
public init(jsonString: String) {
|
||||
self.nativeLanguageByCountry = (try? JSONDecoder().decode(Dictionary<String, String>.self, from: jsonString.data(using: .utf8) ?? Data())) ?? [:]
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
let nativeLanguageByCountryData = decoder.decodeBytesForKey("nativeLanguageByCountry")!
|
||||
self.nativeLanguageByCountry = (try? JSONDecoder().decode(Dictionary<String, String>.self, from: nativeLanguageByCountryData.dataNoCopy())) ?? [:]
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
let nativeLanguageByCountryData = (try? JSONEncoder().encode(self.nativeLanguageByCountry)) ?? Data()
|
||||
encoder.encodeBytes(MemoryBuffer(data: nativeLanguageByCountryData), forKey: "nativeLanguageByCountry")
|
||||
}
|
||||
}
|
||||
|
||||
public final class CachedSecureIdConfiguration: PostboxCoding {
|
||||
public let value: SecureIdConfiguration
|
||||
public let hash: Int32
|
||||
|
||||
public init(value: SecureIdConfiguration, hash: Int32) {
|
||||
self.value = value
|
||||
self.hash = hash
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.value = decoder.decodeObjectForKey("value", decoder: { SecureIdConfiguration(decoder: $0) }) as! SecureIdConfiguration
|
||||
self.hash = decoder.decodeInt32ForKey("hash", orElse: 0)
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeObject(self.value, forKey: "value")
|
||||
encoder.encodeInt32(self.hash, forKey: "hash")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user