mirror of
https://github.com/JoelBender/modpypes
synced 2025-10-19 21:30:44 +08:00
rip out the _ord hack, struct.unpack is faster in py2 and ever so slightly slower in py3, not different enough to justify the hack
This commit is contained in:
parent
fca91ea457
commit
793263db9d
|
@ -7,6 +7,7 @@ Application
|
|||
"""
|
||||
|
||||
import sys
|
||||
import struct
|
||||
|
||||
from bacpypes.debugging import bacpypes_debugging, ModuleLogger
|
||||
|
||||
|
@ -21,17 +22,6 @@ _debug = 0
|
|||
_log = ModuleLogger(globals())
|
||||
|
||||
|
||||
#
|
||||
# _ord
|
||||
#
|
||||
|
||||
if sys.version_info[0] == 2:
|
||||
_ord = lambda s: ord(s)
|
||||
elif sys.version_info[0] == 3:
|
||||
_ord = lambda s: s
|
||||
else:
|
||||
raise RuntimeError("unrecognized Python version")
|
||||
|
||||
#
|
||||
# ModbusException
|
||||
#
|
||||
|
@ -80,8 +70,8 @@ def stream_to_packet(data):
|
|||
if len(data) < 6:
|
||||
return None
|
||||
|
||||
# note funky _ord function, a noop in Python3
|
||||
pktlen = (_ord(data[4]) << 8) + _ord(data[5]) + 6
|
||||
# unpack the length
|
||||
pktlen = struct.unpack(">H", data[4:6])[0] + 6
|
||||
if (len(data) < pktlen):
|
||||
return None
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user