1
0
mirror of https://github.com/JoelBender/modpypes synced 2025-10-26 21:49:19 +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:
Joel Bender 2017-04-28 09:24:50 -04:00
parent fca91ea457
commit 793263db9d

View File

@ -7,6 +7,7 @@ Application
""" """
import sys import sys
import struct
from bacpypes.debugging import bacpypes_debugging, ModuleLogger from bacpypes.debugging import bacpypes_debugging, ModuleLogger
@ -21,17 +22,6 @@ _debug = 0
_log = ModuleLogger(globals()) _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 # ModbusException
# #
@ -80,8 +70,8 @@ def stream_to_packet(data):
if len(data) < 6: if len(data) < 6:
return None return None
# note funky _ord function, a noop in Python3 # unpack the length
pktlen = (_ord(data[4]) << 8) + _ord(data[5]) + 6 pktlen = struct.unpack(">H", data[4:6])[0] + 6
if (len(data) < pktlen): if (len(data) < pktlen):
return None return None