mirror of
https://github.com/barronwaffles/dwc_network_server_emulator.git
synced 2026-08-23 19:15:09 -05:00
Add optional overload to the get_short and get_int functions
This commit is contained in:
@@ -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):
|
||||||
|
|||||||
Reference in New Issue
Block a user