added ability to read VarInt off socket

This commit is contained in:
əlemi 2021-10-10 16:21:05 +02:00 committed by alemidev
parent e8d27ca4b7
commit 5b00b69216

View file

@ -62,6 +62,15 @@ class VarInt(Type):
_pytype : type = int
_maxBytes = 5
@classmethod
async def read(cls, stream: asyncio.StreamReader) -> int:
buf = 0b10000000
off = 0
while (buf & 0b0000000) != 0:
buf |= (await stream.read(1)) >> (7*off)
off += 1
return buf
@classmethod
def serialize(cls, data:int) -> bytes:
res : bytearray = bytearray()