updated reading to read until you see a message for your stream (#100)

* updated reading to read until you see a message for your stream

* added timeout to decode uvarint

* resolved comments

* shortened long line
This commit is contained in:
Alex Haynes
2019-01-28 16:15:22 -05:00
committed by GitHub
parent fa4895dad8
commit 7736d2afd2
3 changed files with 204 additions and 16 deletions

View File

@ -29,12 +29,11 @@ def decode_uvarint(buff, index):
return result, index + 1
async def decode_uvarint_from_stream(reader):
async def decode_uvarint_from_stream(reader, timeout):
shift = 0
result = 0
while True:
byte = await asyncio.wait_for(reader.read(1), timeout=5)
byte = await asyncio.wait_for(reader.read(1), timeout=timeout)
i = struct.unpack('>H', b'\x00' + byte)[0]
result |= (i & 0x7f) << shift
shift += 7