Move MessageContainer.on_send inside its .to_bytes

This commit is contained in:
Lonami Exo 2017-09-27 13:49:58 +02:00
parent 6df9fc558e
commit 795cb98909

View File

@ -14,25 +14,22 @@ class MessageContainer(TLObject):
self.session = session
self.requests = requests
def on_send(self, writer):
writer.write_int(MessageContainer.constructor_id, signed=False)
writer.write_int(len(self.requests))
for x in self.requests:
x.request_msg_id = self.session.get_new_msg_id()
writer.write_long(x.request_msg_id)
writer.write_int(
self.session.generate_sequence(x.content_related)
)
packet = GzipPacked.gzip_if_smaller(x)
writer.write_int(len(packet))
writer.write(packet)
def to_bytes(self):
# TODO Change this to delete the on_send from this class
with BinaryWriter() as writer:
self.on_send(writer)
writer.write_int(MessageContainer.constructor_id, signed=False)
writer.write_int(len(self.requests))
for x in self.requests:
x.request_msg_id = self.session.get_new_msg_id()
writer.write_long(x.request_msg_id)
writer.write_int(
self.session.generate_sequence(x.content_related)
)
packet = GzipPacked.gzip_if_smaller(x)
writer.write_int(len(packet))
writer.write(packet)
return writer.get_bytes()
@staticmethod