@@ 120-145 (lines=26) @@ | ||
117 | return ceil(current_size / 8) * 8 |
|
118 | raise ValueError(f'Invalid value "{value}" for Action*.get_size()') |
|
119 | ||
120 | def unpack(self, buff, offset=0): |
|
121 | """Unpack a binary message into this object's attributes. |
|
122 | ||
123 | Unpack the binary value *buff* and update this object attributes based |
|
124 | on the results. |
|
125 | ||
126 | Args: |
|
127 | buff (bytes): Binary data package to be unpacked. |
|
128 | offset (int): Where to begin unpacking. |
|
129 | ||
130 | Raises: |
|
131 | Exception: If there is a struct unpacking error. |
|
132 | ||
133 | """ |
|
134 | self.action_type = UBInt16(enum_ref=ActionType) |
|
135 | self.action_type.unpack(buff, offset) |
|
136 | ||
137 | self.length = UBInt16() |
|
138 | self.length.unpack(buff, offset=offset+2) |
|
139 | ||
140 | for cls in ActionHeader.__subclasses__(): |
|
141 | if self.action_type.value in cls.get_allowed_types(): |
|
142 | self.__class__ = cls |
|
143 | break |
|
144 | ||
145 | super().unpack(buff[:offset+self.length], offset) |
|
146 | ||
147 | @classmethod |
|
148 | def get_allowed_types(cls): |
@@ 79-101 (lines=23) @@ | ||
76 | self.action_type = action_type |
|
77 | self.length = length |
|
78 | ||
79 | def unpack(self, buff, offset=0): |
|
80 | """Unpack a binary message into this object's attributes. |
|
81 | ||
82 | Unpack the binary value *buff* and update this object attributes based |
|
83 | on the results. |
|
84 | ||
85 | Args: |
|
86 | buff (bytes): Binary data package to be unpacked. |
|
87 | offset (int): Where to begin unpacking. |
|
88 | ||
89 | Raises: |
|
90 | Exception: If there is a struct unpacking error. |
|
91 | ||
92 | """ |
|
93 | self.action_type = UBInt16(enum_ref=ActionType) |
|
94 | self.action_type.unpack(buff, offset) |
|
95 | ||
96 | for cls in ActionHeader.__subclasses__(): |
|
97 | if self.action_type.value in cls.get_allowed_types(): |
|
98 | self.__class__ = cls |
|
99 | break |
|
100 | ||
101 | super().unpack(buff, offset) |
|
102 | ||
103 | @classmethod |
|
104 | def get_allowed_types(cls): |