mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
Add delim_encode and delim_read
- Add `StreamCommunicator` and `RawConnectionCommunicator`, read/write messages with delim codec, with `IMuxedStream` and `IRawConnection` respectively. - Use it in `Multiselect` and `MultiselectClient`.
This commit is contained in:
committed by
Kevin Mai-Husan Chia
parent
8cd23abfe2
commit
86d4ce1da8
@ -2,6 +2,8 @@ import asyncio
|
||||
import struct
|
||||
from typing import Tuple
|
||||
|
||||
from libp2p.typing import StreamReader
|
||||
|
||||
|
||||
def encode_uvarint(number: int) -> bytes:
|
||||
"""Pack `number` into varint bytes"""
|
||||
@ -31,9 +33,7 @@ def decode_uvarint(buff: bytes, index: int) -> Tuple[int, int]:
|
||||
return result, index + 1
|
||||
|
||||
|
||||
async def decode_uvarint_from_stream(
|
||||
reader: asyncio.StreamReader, timeout: float
|
||||
) -> int:
|
||||
async def decode_uvarint_from_stream(reader: StreamReader, timeout: float) -> int:
|
||||
shift = 0
|
||||
result = 0
|
||||
while True:
|
||||
|
||||
Reference in New Issue
Block a user