diff --git a/example/swift/src/main.swift b/example/swift/src/main.swift index a934decf7..1826459dc 100644 --- a/example/swift/src/main.swift +++ b/example/swift/src/main.swift @@ -7,13 +7,13 @@ class TdClient { let tdlibMainLoop = DispatchQueue(label: "TDLib") let tdlibQueryQueue = DispatchQueue(label: "TDLibQuery") var queryF = Dictionary)->()>() - var updateF : ((Dictionary)->())? - var queryId : Int64 = 0 - + var updateF: ((Dictionary)->())? + var queryId: Int64 = 0 + func queryAsync(query: [String: Any], f: ((Dictionary)->())? = nil) { tdlibQueryQueue.async { var newQuery = query - + if f != nil { let nextQueryId = self.queryId + 1 newQuery["@extra"] = nextQueryId @@ -23,7 +23,7 @@ class TdClient { td_json_client_send(self.client, to_json(newQuery)) } } - + func querySync(query: [String: Any]) -> Dictionary { let semaphore = DispatchSemaphore(value:0) var result = Dictionary() @@ -33,9 +33,8 @@ class TdClient { } semaphore.wait() return result - } - + init() { } @@ -48,7 +47,7 @@ class TdClient { tdlibMainLoop.async { [weak self] in while (true) { if let s = self { - if let res = td_json_client_receive(s.client,10) { + if let res = td_json_client_receive(s.client, 10) { let event = String(cString: res) s.queryResultAsync(event) } @@ -58,11 +57,11 @@ class TdClient { } } } - + private func queryResultAsync(_ result: String) { tdlibQueryQueue.async { let json = try? JSONSerialization.jsonObject(with: result.data(using: .utf8)!, options:[]) - if let dictionary = json as? [String:Any] { + if let dictionary = json as? [String:Any] { if let extra = dictionary["@extra"] as? Int64 { let index = self.queryF.index(forKey: extra)! self.queryF[index].value(dictionary) @@ -75,7 +74,7 @@ class TdClient { } } -func to_json(_ obj: Any) -> String { +func to_json(_ obj: Any) -> String { do { let obj = try JSONSerialization.data(withJSONObject: obj) return String(data: obj, encoding: .utf8)! @@ -98,7 +97,7 @@ func myReadLine() -> String { } } -func updateAuthorizationState(authState : Dictionary) { +func updateAuthorizationState(authState: Dictionary) { switch(authState["@type"] as! String) { case "authorizationStateWaitTdlibParameters": client.queryAsync(query:[ @@ -118,19 +117,19 @@ func updateAuthorizationState(authState : Dictionary) { case "authorizationStateWaitEncryptionKey": client.queryAsync(query: ["@type":"checkDatabaseEncryptionKey", "key":"cucumber"]) - + case "authorizationStateWaitPhoneNumber": print("Enter your phone: ") let phone = myReadLine() client.queryAsync(query:["@type":"setAuthenticationPhoneNumber", "phone_number":phone], f:checkAuthError) - + case "authorizationStateWaitCode": - var first_name : String = "" + var first_name: String = "" var last_name: String = "" - var code : String = "" + var code: String = "" if let is_registered = authState["is_registered"] as? Bool, is_registered { } else { - print("Enter your first name : ") + print("Enter your first name: ") first_name = myReadLine() print("Enter your last name: ") last_name = myReadLine() @@ -169,5 +168,3 @@ client.run { while true { sleep(1) } - - diff --git a/tdutils/td/utils/tl_parsers.cpp b/tdutils/td/utils/tl_parsers.cpp index 7a44f3f8c..534e7793c 100644 --- a/tdutils/td/utils/tl_parsers.cpp +++ b/tdutils/td/utils/tl_parsers.cpp @@ -8,7 +8,7 @@ namespace td { -alignas(128) const unsigned char TlParser::empty_data[sizeof(UInt256)] = {}; // static zero-initialized +alignas(4) const unsigned char TlParser::empty_data[sizeof(UInt256)] = {}; // static zero-initialized void TlParser::set_error(const string &error_message) { if (error.empty()) { diff --git a/tdutils/td/utils/tl_parsers.h b/tdutils/td/utils/tl_parsers.h index 009da33f3..ffb669bde 100644 --- a/tdutils/td/utils/tl_parsers.h +++ b/tdutils/td/utils/tl_parsers.h @@ -33,7 +33,7 @@ class TlParser { static constexpr size_t SMALL_DATA_ARRAY_SIZE = 6; std::array small_data_array; - static const unsigned char empty_data[sizeof(UInt256)]; + alignas(4) static const unsigned char empty_data[sizeof(UInt256)]; public: explicit TlParser(Slice slice) {