mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-25 10:53:44 +03:00
Added ability to both read and write vectors*
This change affects the BinaryReader and BinaryWriter Note that it only allows to write vectors of **TLObjects**, not any other type
This commit is contained in:
parent
36b8a9026f
commit
ded655911e
|
@ -128,6 +128,14 @@ class BinaryReader:
|
||||||
result.on_response(self)
|
result.on_response(self)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def tgread_vector(self):
|
||||||
|
"""Reads a vector (a list) of Telegram objects"""
|
||||||
|
if 0x1cb5c415 != self.read_int(signed=False):
|
||||||
|
raise ValueError('Invalid constructor code, vector was expected')
|
||||||
|
|
||||||
|
count = self.read_int()
|
||||||
|
return [self.tgread_object() for _ in range(count)]
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
|
|
@ -95,6 +95,17 @@ class BinaryWriter:
|
||||||
value = 0 if datetime is None else int(datetime.timestamp())
|
value = 0 if datetime is None else int(datetime.timestamp())
|
||||||
self.write_int(value)
|
self.write_int(value)
|
||||||
|
|
||||||
|
def tgwrite_object(self, tlobject):
|
||||||
|
"""Writes a Telegram object"""
|
||||||
|
tlobject.on_send(self)
|
||||||
|
|
||||||
|
def tgwrite_vector(self, vector):
|
||||||
|
"""Writes a vector of Telegram objects"""
|
||||||
|
self.write_int(0x1cb5c415, signed=False) # Vector's constructor ID
|
||||||
|
self.write_int(len(vector))
|
||||||
|
for item in vector:
|
||||||
|
self.tgwrite_object(item)
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user