mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Refactoring
This commit is contained in:
@@ -17,7 +17,7 @@ extension _AdaptedPostboxEncoder {
|
||||
self.encoder = PostboxEncoder()
|
||||
}
|
||||
|
||||
func makeData(addHeader: Bool) -> (Data, ValueType) {
|
||||
func makeData(addHeader: Bool, isDictionary: Bool) -> (Data, ValueType) {
|
||||
let buffer = WriteBuffer()
|
||||
|
||||
if addHeader {
|
||||
@@ -43,12 +43,27 @@ extension _AdaptedPostboxEncoder.KeyedContainer: KeyedEncodingContainerProtocol
|
||||
func encode<T>(_ value: T, forKey key: Key) throws where T : Encodable {
|
||||
if let value = value as? Data {
|
||||
self.encoder.encodeData(value, forKey: key.stringValue)
|
||||
} else if let value = value as? AdaptedPostboxEncoder.RawObjectData {
|
||||
let typeHash: Int32 = value.typeHash
|
||||
let innerEncoder = _AdaptedPostboxEncoder(typeHash: typeHash)
|
||||
try! value.encode(to: innerEncoder)
|
||||
|
||||
let (data, valueType) = innerEncoder.makeData(addHeader: true, isDictionary: false)
|
||||
self.encoder.encodeInnerObjectData(data, valueType: valueType, forKey: key.stringValue)
|
||||
} else {
|
||||
let typeHash: Int32 = murMurHashString32("\(type(of: value))")
|
||||
let innerEncoder = _AdaptedPostboxEncoder(typeHash: typeHash)
|
||||
try! value.encode(to: innerEncoder)
|
||||
|
||||
let (data, valueType) = innerEncoder.makeData(addHeader: true)
|
||||
let type = type(of: value)
|
||||
let typeString = "\(type)"
|
||||
var isDictionary = false
|
||||
if typeString.hasPrefix("Dictionary<") {
|
||||
isDictionary = true
|
||||
}
|
||||
|
||||
let (data, valueType) = innerEncoder.makeData(addHeader: true, isDictionary: isDictionary)
|
||||
|
||||
self.encoder.encodeInnerObjectData(data, valueType: valueType, forKey: key.stringValue)
|
||||
}
|
||||
}
|
||||
@@ -65,6 +80,12 @@ extension _AdaptedPostboxEncoder.KeyedContainer: KeyedEncodingContainerProtocol
|
||||
self.encoder.encodeInt64(value, forKey: key.stringValue)
|
||||
}
|
||||
|
||||
func encode(_ value: Int, forKey key: Key) throws {
|
||||
assertionFailure()
|
||||
|
||||
self.encoder.encodeInt32(Int32(value), forKey: key.stringValue)
|
||||
}
|
||||
|
||||
func encode(_ value: Bool, forKey key: Key) throws {
|
||||
self.encoder.encodeBool(value, forKey: key.stringValue)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user