From b64ed9fd6f575530cef5bb1f6a6b19e123b42aa0 Mon Sep 17 00:00:00 2001 From: Chih Cheng Liang Date: Fri, 2 Aug 2019 17:57:30 +0800 Subject: [PATCH] typed mplex.utils --- libp2p/stream_muxer/mplex/utils.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libp2p/stream_muxer/mplex/utils.py b/libp2p/stream_muxer/mplex/utils.py index 7bd57729..07f62fb7 100644 --- a/libp2p/stream_muxer/mplex/utils.py +++ b/libp2p/stream_muxer/mplex/utils.py @@ -1,8 +1,10 @@ import asyncio import struct +from typing import Tuple -def encode_uvarint(number): + +def encode_uvarint(number: int) -> bytearray: """Pack `number` into varint bytes""" buf = b"" while True: @@ -16,7 +18,7 @@ def encode_uvarint(number): return buf -def decode_uvarint(buff, index): +def decode_uvarint(buff: bytearray, index: int) -> Tuple[int, int]: shift = 0 result = 0 while True: @@ -30,7 +32,9 @@ def decode_uvarint(buff, index): return result, index + 1 -async def decode_uvarint_from_stream(reader, timeout): +async def decode_uvarint_from_stream( + reader: asyncio.StreamReader, timeout: float +) -> int: shift = 0 result = 0 while True: