ULEB
This commit is contained in:
@@ -20,6 +20,30 @@ BYTEORDER_NATIVE = b"@"
|
||||
BYTEORDER_LITTLE = b"<"
|
||||
BYTEORDER_BIG = b">"
|
||||
|
||||
def encode_uleb(val):
|
||||
data = b""
|
||||
pos = 0
|
||||
while val != 0:
|
||||
b = val & 0x7f
|
||||
val >>= 7
|
||||
if val != 0:
|
||||
b |= 0x80
|
||||
data += bytes([b])
|
||||
return data
|
||||
|
||||
def decode_uleb(data):
|
||||
val = 0
|
||||
shift = 0
|
||||
pos = 0
|
||||
while True:
|
||||
b = data[pos]
|
||||
pos += 1
|
||||
val |= (b & 0x7f) << shift
|
||||
if (b & 0x80) == 0:
|
||||
break
|
||||
shift += 7
|
||||
return val, pos
|
||||
|
||||
def guess_type(value):
|
||||
t_value = type(value)
|
||||
|
||||
@@ -70,7 +94,7 @@ class Serializable:
|
||||
def get_value(self):
|
||||
def _get_value():
|
||||
if self.type == TYPE_STRING:
|
||||
return [11, bytes([len(self.value)]) + self.value]
|
||||
return [0x0b, encode_uleb(len(self.value)) + self.value]
|
||||
return [self.value]
|
||||
|
||||
val = _get_value()
|
||||
|
||||
Reference in New Issue
Block a user