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 = num >> 7 if num != 0: arr[length] = 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] = 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 = "