Initialize each fields of the fields_desc dict, or use the cached fields information
(self, for_dissect_only=False)
| 301 | self.default_fields = default_fields |
| 302 | |
| 303 | def do_init_cached_fields(self, for_dissect_only=False): |
| 304 | # type: (bool) -> None |
| 305 | """ |
| 306 | Initialize each fields of the fields_desc dict, or use the cached |
| 307 | fields information |
| 308 | """ |
| 309 | |
| 310 | cls_name = self.__class__ |
| 311 | |
| 312 | # Build the fields information |
| 313 | if Packet.class_default_fields.get(cls_name, None) is None: |
| 314 | self.prepare_cached_fields(self.fields_desc) |
| 315 | |
| 316 | # Use fields information from cache |
| 317 | default_fields = Packet.class_default_fields.get(cls_name, None) |
| 318 | if default_fields: |
| 319 | self.default_fields = default_fields |
| 320 | self.fieldtype = Packet.class_fieldtype[cls_name] |
| 321 | self.packetfields = Packet.class_packetfields[cls_name] |
| 322 | |
| 323 | # Optimization: no need for references when only dissecting. |
| 324 | if for_dissect_only: |
| 325 | return |
| 326 | |
| 327 | # Deepcopy default references |
| 328 | for fname in Packet.class_default_fields_ref[cls_name]: |
| 329 | value = self.default_fields[fname] |
| 330 | try: |
| 331 | self.fields[fname] = value.copy() |
| 332 | except AttributeError: |
| 333 | # Python 2.7 - list only |
| 334 | self.fields[fname] = value[:] |
| 335 | |
| 336 | def prepare_cached_fields(self, flist): |
| 337 | # type: (Sequence[AnyField]) -> None |
no test coverage detected