Add optional overload to the get_short and get_int functions

This commit is contained in:
polaris
2014-07-29 09:46:28 -04:00
parent 07de306dbd
commit 97277fb9b0

View File

@@ -91,18 +91,18 @@ def base32_decode(s, reverse=False):
# Number routines # Number routines
def get_num_from_bytes(data, idx, fmt, bigEndian=False): def get_num_from_bytes(data, idx, fmt, bigEndian=False):
return struct.unpack_from("<>"[bigEndian] + fmt, data, idx)[0] return struct.unpack_from("<>"[bigEndian] + fmt, bytearray(data), idx)[0]
# Instead of passing slices, pass the buffer and index so we can calculate # Instead of passing slices, pass the buffer and index so we can calculate
# the length automatically. # the length automatically.
def get_short(data, idx): def get_short(data, idx, bigEndian=False):
return get_num_from_bytes(data, idx, 'h', False) return get_num_from_bytes(data, idx, 'h', bigEndian)
def get_int(data, idx): def get_int(data, idx, bigEndian=False):
return get_num_from_bytes(data, idx, 'i', False) return get_num_from_bytes(data, idx, 'i', bigEndian)
def get_string(data, idx): def get_string(data, idx):