Compare commits
1 Commits
mtpager
...
fix-vector
Author | SHA1 | Date | |
---|---|---|---|
|
e3f1642797 |
@ -19,7 +19,7 @@
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from typing import cast, Union, Any
|
from typing import cast, Union, Any
|
||||||
|
|
||||||
from .int import Int
|
from .int import Int, Long
|
||||||
from ..list import List
|
from ..list import List
|
||||||
from ..tl_object import TLObject
|
from ..tl_object import TLObject
|
||||||
|
|
||||||
@ -30,19 +30,29 @@ class Vector(bytes, TLObject):
|
|||||||
# Method added to handle the special case when a query returns a bare Vector (of Ints);
|
# Method added to handle the special case when a query returns a bare Vector (of Ints);
|
||||||
# i.e., RpcResult body starts with 0x1cb5c415 (Vector Id) - e.g., messages.GetMessagesViews.
|
# i.e., RpcResult body starts with 0x1cb5c415 (Vector Id) - e.g., messages.GetMessagesViews.
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _read(b: BytesIO) -> Union[int, Any]:
|
def read_bare(b: BytesIO, n: int) -> Union[int, Any]:
|
||||||
|
left = len(b.read())
|
||||||
|
size = left // n
|
||||||
|
b.seek(-left, 1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return TLObject.read(b)
|
return TLObject.read(b)
|
||||||
except ValueError:
|
except KeyError:
|
||||||
b.seek(-4, 1)
|
b.seek(-4, 1)
|
||||||
|
|
||||||
|
if size == 4:
|
||||||
return Int.read(b)
|
return Int.read(b)
|
||||||
|
else:
|
||||||
|
return Long.read(b)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def read(cls, data: BytesIO, t: Any = None, *args: Any) -> List:
|
def read(cls, data: BytesIO, t: Any = None, *args: Any) -> List:
|
||||||
|
count = Int.read(data)
|
||||||
|
|
||||||
return List(
|
return List(
|
||||||
t.read(data) if t
|
t.read(data) if t
|
||||||
else Vector._read(data)
|
else Vector.read_bare(data, count)
|
||||||
for _ in range(Int.read(data))
|
for _ in range(count)
|
||||||
)
|
)
|
||||||
|
|
||||||
def __new__(cls, value: list, t: Any = None) -> bytes: # type: ignore
|
def __new__(cls, value: list, t: Any = None) -> bytes: # type: ignore
|
||||||
|
Loading…
Reference in New Issue
Block a user