mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Refactoring
This commit is contained in:
@@ -589,7 +589,7 @@ public final class PostboxEncoder {
|
||||
let innerEncoder = _AdaptedPostboxEncoder(typeHash: typeHash)
|
||||
try! value.encode(to: innerEncoder)
|
||||
|
||||
let (data, valueType) = innerEncoder.makeData()
|
||||
let (data, valueType) = innerEncoder.makeData(addHeader: true)
|
||||
self.encodeInnerObjectData(data, valueType: valueType, forKey: key)
|
||||
}
|
||||
|
||||
@@ -1612,6 +1612,29 @@ public final class PostboxDecoder {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
static func parseDataRaw(data: Data) -> Data? {
|
||||
return data.withUnsafeBytes { bytes -> Data? in
|
||||
guard let baseAddress = bytes.baseAddress else {
|
||||
return nil
|
||||
}
|
||||
if bytes.count < 4 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var length: Int32 = 0
|
||||
memcpy(&length, baseAddress, 4)
|
||||
|
||||
if length < 0 || length != (bytes.count - 4) {
|
||||
return nil
|
||||
}
|
||||
if length == 0 {
|
||||
return Data()
|
||||
}
|
||||
|
||||
return Data(bytes: baseAddress.advanced(by: 4), count: Int(length))
|
||||
}
|
||||
}
|
||||
|
||||
public func decodeDataForKey(_ key: String) -> Data? {
|
||||
if PostboxDecoder.positionOnKey(self.buffer.memory, offset: &self.offset, maxOffset: self.buffer.length, length: self.buffer.length, key: key, valueType: .Bytes) {
|
||||
|
||||
Reference in New Issue
Block a user