1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00

wire: use memoryview() asap in the parsing process

This commit is contained in:
Jan Pochyla 2016-10-20 15:13:08 +02:00
parent 67ac47f087
commit 688d293b01
3 changed files with 11 additions and 7 deletions

View File

@ -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:

View File

@ -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

View File

@ -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)