import struct from constants import dataTypes def uleb128Encode(num): """ Encode int -> uleb128 num -- int to encode return -- bytearray with encoded number """ arr = bytearray() length = 0 if num == 0: return bytearray(b"\x00") while num > 0: arr.append(num & 127) num >>= 7 if num != 0: arr[length] |= 128 length+=1 return arr def uleb128Decode(num): """ Decode uleb128 -> int num -- encoded uleb128 return -- list. [total, length] """ shift = 0 arr = [0,0] #total, length while True: b = num[arr[1]] arr[1]+=1 arr[0] |= int(b & 127) << shift if b & 128 == 0: break shift += 7 return arr def unpackData(data, dataType): """ Unpacks data according to dataType data -- bytes array to unpack dataType -- data type. See dataTypes.py return -- unpacked bytes """ # Get right pack Type if dataType == dataTypes.UINT16: unpackType = "