mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-11-13 20:40:36 +00:00
Pre-pack outgoing TLMessage
This has several benefits: - The message can be resent without re-calling bytes(), which for some requests may be expensive. - Converting requests to bytes early lets us detect errors early, such as OverflowError on bad requests. - Containers can't exceed 1044456 bytes so knowing their length is important. This can now be done in O(1). But also several drawbacks: - If the object is modified the bytes won't reflect this. This isn't an issue because it's only done for in msgs. - Incoming messages can no longer be reconverted into bytes but this was never needed anyway.
This commit is contained in:
@@ -507,7 +507,6 @@ class MTProtoSender:
|
||||
rpc_result.req_msg_id)
|
||||
|
||||
if rpc_result.error:
|
||||
# TODO Report errors if possible/enabled
|
||||
error = rpc_message_to_error(rpc_result.error)
|
||||
self._send_queue.put_nowait(self.state.create_message(
|
||||
MsgsAck([message.msg_id])
|
||||
@@ -517,10 +516,13 @@ class MTProtoSender:
|
||||
message.future.set_exception(error)
|
||||
return
|
||||
elif message:
|
||||
# TODO Would be nice to avoid accessing a per-obj read_result
|
||||
# Instead have a variable that indicated how the result should
|
||||
# be read (an enum) and dispatch to read the result, mostly
|
||||
# always it's just a normal TLObject.
|
||||
with BinaryReader(rpc_result.body) as reader:
|
||||
result = message.obj.read_result(reader)
|
||||
|
||||
# TODO Process entities
|
||||
if not message.future.cancelled():
|
||||
message.future.set_result(result)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user