mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
typed mplex.utils
This commit is contained in:
@ -1,8 +1,10 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
|
from typing import Tuple
|
||||||
|
|
||||||
def encode_uvarint(number):
|
|
||||||
|
def encode_uvarint(number: int) -> bytearray:
|
||||||
"""Pack `number` into varint bytes"""
|
"""Pack `number` into varint bytes"""
|
||||||
buf = b""
|
buf = b""
|
||||||
while True:
|
while True:
|
||||||
@ -16,7 +18,7 @@ def encode_uvarint(number):
|
|||||||
return buf
|
return buf
|
||||||
|
|
||||||
|
|
||||||
def decode_uvarint(buff, index):
|
def decode_uvarint(buff: bytearray, index: int) -> Tuple[int, int]:
|
||||||
shift = 0
|
shift = 0
|
||||||
result = 0
|
result = 0
|
||||||
while True:
|
while True:
|
||||||
@ -30,7 +32,9 @@ def decode_uvarint(buff, index):
|
|||||||
return result, index + 1
|
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
|
shift = 0
|
||||||
result = 0
|
result = 0
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
Reference in New Issue
Block a user