use 16 bit num field for variable length message types
This commit is contained in:
parent
8b779e257b
commit
0ff2bdcd00
1 changed files with 8 additions and 17 deletions
|
@ -244,17 +244,8 @@ class FixedHexFormat(SimpleFormat):
|
|||
|
||||
@abstractmethod
|
||||
class BaseVarFormat(BaseFormat, ABC):
|
||||
def __init__(self, max_num, num_fmt=None):
|
||||
if num_fmt is None:
|
||||
if max_num < 2 ** 8:
|
||||
num_fmt = 'B'
|
||||
elif max_num < 2 ** 16:
|
||||
num_fmt = 'H'
|
||||
elif max_num < 2 ** 32:
|
||||
num_fmt = 'I'
|
||||
else:
|
||||
num_fmt = 'Q'
|
||||
self.num_fmt = num_fmt
|
||||
def __init__(self, max_num):
|
||||
self.num_fmt = 'H'
|
||||
self.num_size = struct.calcsize(self.num_fmt)
|
||||
self.max_num = max_num
|
||||
|
||||
|
@ -269,8 +260,8 @@ class BaseVarFormat(BaseFormat, ABC):
|
|||
|
||||
|
||||
class VarArrayFormat(BaseVarFormat):
|
||||
def __init__(self, child_type, max_num, num_fmt=None):
|
||||
super().__init__(num_fmt=num_fmt, max_num=max_num)
|
||||
def __init__(self, child_type, max_num):
|
||||
super().__init__(max_num=max_num)
|
||||
self.child_type = child_type
|
||||
self.child_size = self.child_type.get_min_size()
|
||||
|
||||
|
@ -314,8 +305,8 @@ class VarArrayFormat(BaseVarFormat):
|
|||
|
||||
|
||||
class VarStrFormat(BaseVarFormat):
|
||||
def __init__(self, max_len, num_fmt=None):
|
||||
super().__init__(max_num=max_len, num_fmt=num_fmt)
|
||||
def __init__(self, max_len):
|
||||
super().__init__(max_num=max_len)
|
||||
|
||||
def get_var_num(self):
|
||||
return 1
|
||||
|
@ -337,8 +328,8 @@ class VarStrFormat(BaseVarFormat):
|
|||
|
||||
|
||||
class VarBytesFormat(BaseVarFormat):
|
||||
def __init__(self, max_size, num_fmt=None):
|
||||
super().__init__(max_num=max_size, num_fmt=num_fmt)
|
||||
def __init__(self, max_size):
|
||||
super().__init__(max_num=max_size)
|
||||
|
||||
def get_var_num(self):
|
||||
return 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue