converted hardcoded host/port to arg driven, switched int.from_bytes to Python2 friendly routine

This commit is contained in:
Randy Gelhausen 2016-11-29 22:50:09 -05:00
parent 8fa999b877
commit bd22551669

View file

@ -13,9 +13,10 @@ Licensed under MIT License. See LICENSE.
import socket
import struct
import sys
HOST = '0.0.0.0'
PORT = 9001
HOST = sys.argv[1]
PORT = int(sys.argv[2])
field_types = {
1: 'IN_BYTES',
@ -151,7 +152,9 @@ class DataFlowSet:
dataslice = data[offset:offset+flen]
# Better solution than struct.unpack with variable field length
fdata = int.from_bytes(dataslice, byteorder='big')
fdata = 0
for idx, byte in enumerate(reversed(bytearray(dataslice))):
fdata += byte << (idx * 8)
new_record.data[fkey] = fdata