mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 22:38:08 +00:00
wire: use memoryview() asap in the parsing process
This commit is contained in:
parent
67ac47f087
commit
688d293b01
@ -76,8 +76,10 @@ Receives report payloads.
|
||||
Sends (msg_type, data_len) to target, followed by data chunks.
|
||||
Throws EOFError after last data chunk, in case of valid checksum.
|
||||
Throws MessageChecksumError to target if data doesn't match the checksum.
|
||||
|
||||
Pass report payloads as `memoryview` for cheaper slicing.
|
||||
'''
|
||||
message = memoryview((yield)) # read first report
|
||||
message = yield # read first report
|
||||
msg_type, data_len, data_tail = parse_message(message)
|
||||
|
||||
target = genfunc(msg_type, data_len, session_id, *args)
|
||||
@ -95,7 +97,7 @@ Throws MessageChecksumError to target if data doesn't match the checksum.
|
||||
checksum = ubinascii.crc32(data_chunk, checksum)
|
||||
|
||||
if data_len > 0:
|
||||
data_tail = memoryview((yield)) # read next report
|
||||
data_tail = yield # read next report
|
||||
|
||||
msg_footer = data_tail[:_MSG_FOOTER_LEN]
|
||||
if len(msg_footer) < _MSG_FOOTER_LEN:
|
||||
|
@ -40,6 +40,8 @@ Receives report payloads.
|
||||
Sends (msg_type, data_len) to target, followed by data chunks.
|
||||
Throws EOFError after last data chunk, in case of valid checksum.
|
||||
Throws MessageChecksumError to target if data doesn't match the checksum.
|
||||
|
||||
Pass report payloads as `memoryview` for cheaper slicing.
|
||||
'''
|
||||
|
||||
message = yield # read first report
|
||||
|
@ -1,19 +1,19 @@
|
||||
import ubinascii
|
||||
from ubinascii import hexlify
|
||||
from micropython import const
|
||||
from trezor import msg, loop, log
|
||||
|
||||
_DEFAULT_IFACE = const(0xFF00) # TODO: use proper interface
|
||||
_DEFAULT_IFACE = const(0xFF00) # TODO: use proper interface
|
||||
|
||||
|
||||
def read_report_stream(target, iface=_DEFAULT_IFACE):
|
||||
while True:
|
||||
report, = yield loop.Select(iface)
|
||||
log.debug(__name__, 'read report %s', ubinascii.hexlify(report))
|
||||
target.send(report)
|
||||
log.debug(__name__, 'read report %s', hexlify(report))
|
||||
target.send(memoryview(report))
|
||||
|
||||
|
||||
def write_report_stream(iface=_DEFAULT_IFACE):
|
||||
while True:
|
||||
report = yield
|
||||
log.debug(__name__, 'write report %s', ubinascii.hexlify(report))
|
||||
log.debug(__name__, 'write report %s', hexlify(report))
|
||||
msg.send(iface, report)
|
||||
|
Loading…
Reference in New Issue
Block a user