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:
Lonami Exo
2018-07-07 11:46:21 +02:00
parent b237947af1
commit 33ce702ab9
3 changed files with 49 additions and 15 deletions

View File

@@ -46,7 +46,8 @@ class MTProtoState:
msg_id=self._get_new_msg_id(),
seq_no=self._get_seq_no(isinstance(obj, TLRequest)),
obj=obj,
after_id=after.msg_id if after else None
after_id=after.msg_id if after else None,
out=True # Pre-convert the request into bytes
)
def update_message_id(self, message):