From 97ba0b94c5da04f0d03945baa21c338c77c9dc20 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 25 Jan 2015 22:07:28 +0000 Subject: - correct writing of tokens, especially extended - further code optimizations git-svn-id: http://svn.miranda-ng.org/main/trunk@11911 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- .../WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp') diff --git a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp index a4f79baf17..227857a522 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp @@ -17,11 +17,6 @@ BinTreeNodeWriter::BinTreeNodeWriter(WAConnection* conn, ISocketConnection* conn this->conn = conn; this->out = new ByteArrayOutputStream(2048); this->realOut = connection; - for (int i = 0; i < WAConnection::DICTIONARY_LEN; i++) { - std::string token(WAConnection::dictionary[i]); - if (token.compare("") != 0) - this->tokenMap[token] = i; - } this->dataBegin = 0; } @@ -135,9 +130,9 @@ void BinTreeNodeWriter::writeAttributes(std::map* attributes) void BinTreeNodeWriter::writeString(const std::string& tag) { - std::map::iterator it = this->tokenMap.find(tag); - if (it != this->tokenMap.end()) - writeToken(it->second); + int token = WAConnection::tokenLookup(tag); + if (token != -1) + writeToken(token); else { size_t atIndex = tag.find('@'); if (atIndex == 0 || atIndex == string::npos) @@ -164,12 +159,11 @@ void BinTreeNodeWriter::writeJid(std::string* user, const std::string& server) void BinTreeNodeWriter::writeToken(int intValue) { - if (intValue < 245) - this->out->write(intValue); - else if (intValue <= 500) { - this->out->write(254); - this->out->write(intValue - 245); + if (intValue & 0x100) { + this->out->write(236); + this->out->write(intValue & 0xFF); } + else this->out->write(intValue); } void BinTreeNodeWriter::writeBytes(unsigned char* bytes, int length) -- cgit v1.2.3