DbgMuxPeer: get away from using construct's parse_stream()

This commit is contained in:
Vadim Yanitskiy 2022-03-29 00:24:02 +03:00
parent 45548e0a3e
commit e71875aa12
1 changed files with 9 additions and 2 deletions

11
peer.py
View File

@ -19,7 +19,7 @@
import logging as log
from typing import Any
from construct import Container, Int16ul
from construct import Const, Container, Int16ul
from transport import Transport
from proto import DbgMuxFrame
@ -64,7 +64,14 @@ class DbgMuxPeer:
self.tx_count += 1
def recv(self) -> Container:
c = DbgMuxFrame.Frame.parse_stream(self.io)
frame: bytes = b''
frame += self.io.read(2) # Magic
Const(b'\x42\x42').parse(frame[:2])
frame += self.io.read(2) # Length
length: int = Int16ul.parse(frame[2:])
frame += self.io.read(length) # Rest
c = DbgMuxFrame.Frame.parse(frame)
log.debug('Rx frame (Ns=%03u, Nr=%03u, fcs=0x%04x) %s %s',
c['TxCount'], c['RxCount'], c['FCS'],