mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 14:45:21 +00:00
no message
This commit is contained in:
74
TelegramCore/Serialization.swift
Normal file
74
TelegramCore/Serialization.swift
Normal file
@@ -0,0 +1,74 @@
|
||||
import Foundation
|
||||
import MtProtoKit
|
||||
|
||||
public class BoxedMessage: NSObject {
|
||||
public let body: Any
|
||||
public init(_ body: Any) {
|
||||
self.body = body
|
||||
}
|
||||
|
||||
override public var description: String {
|
||||
get {
|
||||
return "\(self.body)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Serialization: NSObject, MTSerialization {
|
||||
public func currentLayer() -> UInt {
|
||||
return 53
|
||||
}
|
||||
|
||||
public func parseMessage(_ data: Data!) -> AnyObject! {
|
||||
if let body = Api.parse(Buffer(data: data)) {
|
||||
return BoxedMessage(body)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
public func exportAuthorization(_ datacenterId: Int32, data: AutoreleasingUnsafeMutablePointer<NSData?>) -> MTExportAuthorizationResponseParser!
|
||||
{
|
||||
let functionContext = Api.functions.auth.exportAuthorization(dcId: datacenterId)
|
||||
data.pointee = functionContext.1.makeData()
|
||||
return { data -> MTExportedAuthorizationData! in
|
||||
if let exported = functionContext.2(Buffer(data: data)) {
|
||||
switch exported {
|
||||
case let .exportedAuthorization(id, bytes):
|
||||
return MTExportedAuthorizationData(authorizationBytes: bytes.makeData(), authorizationId: id)
|
||||
}
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func importAuthorization(_ authId: Int32, bytes: Data!) -> Data! {
|
||||
return Api.functions.auth.importAuthorization(id: authId, bytes: Buffer(data: bytes)).1.makeData()
|
||||
}
|
||||
|
||||
public func requestDatacenterAddressList(_ datacenterId: Int32, data: AutoreleasingUnsafeMutablePointer<NSData?>) -> MTRequestDatacenterAddressListParser! {
|
||||
let (_, buffer, parse) = Api.functions.help.getConfig()
|
||||
data.pointee = buffer.makeData()
|
||||
return { response -> MTDatacenterAddressListData! in
|
||||
if let config = parse(Buffer(data: response)) {
|
||||
switch config {
|
||||
case let .config(_, _, _, _, dcOptions, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _):
|
||||
var addressList = [MTDatacenterAddress]()
|
||||
for option in dcOptions {
|
||||
switch option {
|
||||
case let .dcOption(flags, id, ipAddress, port) where id == datacenterId:
|
||||
let preferForMedia = (flags & (1 << 1)) != 0
|
||||
addressList.append(MTDatacenterAddress(ip: ipAddress, port: UInt16(port), preferForMedia: preferForMedia, restrictToTcp: false))
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
return MTDatacenterAddressListData(addressList: addressList)
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user