2018-06-09 14:11:49 +03:00
|
|
|
from .tlmessage import TLMessage
|
2018-06-09 14:48:27 +03:00
|
|
|
from ..tlobject import TLObject
|
|
|
|
|
2017-09-25 21:52:27 +03:00
|
|
|
|
|
|
|
class MessageContainer(TLObject):
|
2017-09-29 14:11:33 +03:00
|
|
|
CONSTRUCTOR_ID = 0x73f1f8dc
|
2017-09-25 21:52:27 +03:00
|
|
|
|
2018-07-07 12:58:48 +03:00
|
|
|
# Maximum size in bytes for the inner payload of the container.
|
|
|
|
# Telegram will close the connection if the payload is bigger.
|
|
|
|
# The overhead of the container itself is subtracted.
|
|
|
|
MAXIMUM_SIZE = 1044456 - 8
|
|
|
|
|
2018-11-19 10:29:44 +03:00
|
|
|
# Maximum amount of messages that can't be sent inside a single
|
|
|
|
# container, inclusive. Beyond this limit Telegram will respond
|
|
|
|
# with BAD_MESSAGE 64 (invalid container).
|
2019-02-13 12:16:59 +03:00
|
|
|
#
|
|
|
|
# This limit is not 100% accurate and may in some cases be higher.
|
|
|
|
# However, sending up to 100 requests at once in a single container
|
|
|
|
# is a reasonable conservative value, since it could also depend on
|
|
|
|
# other factors like size per request, but we cannot know this.
|
|
|
|
MAXIMUM_LENGTH = 100
|
2018-11-19 10:29:44 +03:00
|
|
|
|
2017-09-27 22:01:20 +03:00
|
|
|
def __init__(self, messages):
|
|
|
|
self.messages = messages
|
2017-09-25 21:52:27 +03:00
|
|
|
|
2018-06-21 10:52:47 +03:00
|
|
|
def to_dict(self):
|
2017-10-29 22:13:00 +03:00
|
|
|
return {
|
2018-06-21 10:52:47 +03:00
|
|
|
'_': 'MessageContainer',
|
2017-10-29 22:13:00 +03:00
|
|
|
'messages':
|
2018-06-21 10:52:47 +03:00
|
|
|
[] if self.messages is None else [
|
2017-10-29 22:13:00 +03:00
|
|
|
None if x is None else x.to_dict() for x in self.messages
|
2018-06-21 10:52:47 +03:00
|
|
|
],
|
2017-10-29 22:13:00 +03:00
|
|
|
}
|
|
|
|
|
2018-06-09 14:11:49 +03:00
|
|
|
@classmethod
|
|
|
|
def from_reader(cls, reader):
|
|
|
|
# This assumes that .read_* calls are done in the order they appear
|
2018-06-09 14:48:27 +03:00
|
|
|
messages = []
|
|
|
|
for _ in range(reader.read_int()):
|
|
|
|
msg_id = reader.read_long()
|
|
|
|
seq_no = reader.read_int()
|
|
|
|
length = reader.read_int()
|
|
|
|
before = reader.tell_position()
|
2018-06-25 13:54:33 +03:00
|
|
|
obj = reader.tgread_object() # May over-read e.g. RpcResult
|
|
|
|
reader.set_position(before + length)
|
2018-09-29 11:58:45 +03:00
|
|
|
messages.append(TLMessage(msg_id, seq_no, obj))
|
2018-06-09 14:48:27 +03:00
|
|
|
return MessageContainer(messages)
|