| 141 | |
| 142 | |
| 143 | class Packet(Dispatchable): |
| 144 | __typeid__ = -1 |
| 145 | __headercls__ = Header |
| 146 | |
| 147 | def __init__(self, _=None): |
| 148 | super(Packet, self).__init__() |
| 149 | self.header = self.__headercls__() |
| 150 | if isinstance(self.__typeid__, int): |
| 151 | self.header.tag = self.__typeid__ |
| 152 | |
| 153 | @abc.abstractmethod |
| 154 | def __bytearray__(self): |
| 155 | return self.header.__bytearray__() |
| 156 | |
| 157 | def __len__(self): |
| 158 | return len(self.header) + self.header.length |
| 159 | |
| 160 | def __repr__(self): |
| 161 | return "<{cls:s} [tag {tag:02d}] at 0x{id:x}>".format(cls=self.__class__.__name__, tag=self.header.tag, id=id(self)) |
| 162 | |
| 163 | def update_hlen(self): |
| 164 | self.header.length = len(self.__bytearray__()) - len(self.header) |
| 165 | |
| 166 | @abc.abstractmethod |
| 167 | def parse(self, packet): |
| 168 | if self.header.tag == 0: |
| 169 | self.header.parse(packet) |
| 170 | |
| 171 | |
| 172 | class VersionedPacket(Packet): |
no outgoing calls
searching dependent graphs…