Replace TLObject.on_send with the new .to_bytes()

This also replaces some int.to_bytes() calls with a faster
struct.pack (up to x4 faster). This approach is also around
x3 faster than creating a BinaryWriter just to serialize a
TLObject as bytes.
This commit is contained in:
Lonami Exo
2017-09-26 14:36:02 +02:00
parent 2bb26d6389
commit b83cd98ba0
5 changed files with 110 additions and 64 deletions

View File

@@ -71,19 +71,14 @@ class MtProtoSender:
else:
request = MessageContainer(self.session, requests)
with BinaryWriter() as writer:
request.on_send(writer)
self._send_packet(writer.get_bytes(), request)
self._pending_receive.append(request)
self._send_packet(request.to_bytes(), request)
self._pending_receive.append(request)
def _send_acknowledges(self):
"""Sends a messages acknowledge for all those who _need_confirmation"""
if self._need_confirmation:
msgs_ack = MsgsAck(self._need_confirmation)
with BinaryWriter() as writer:
msgs_ack.on_send(writer)
self._send_packet(writer.get_bytes(), msgs_ack)
self._send_packet(msgs_ack.to_bytes(), msgs_ack)
del self._need_confirmation[:]
def receive(self, update_state):