pypcapkit 1.0.3__cp310-none-any.whl → 1.1.0__cp310-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. pcapkit/__init__.py +1 -1
  2. pcapkit/const/pcapng/option_type.py +4 -1
  3. pcapkit/const/reg/apptype.py +19019 -19015
  4. pcapkit/corekit/fields/collections.py +14 -14
  5. pcapkit/corekit/fields/field.py +33 -8
  6. pcapkit/corekit/fields/ipaddress.py +0 -1
  7. pcapkit/corekit/fields/misc.py +14 -19
  8. pcapkit/corekit/fields/numbers.py +2 -3
  9. pcapkit/corekit/fields/strings.py +2 -3
  10. pcapkit/corekit/infoclass.py +59 -6
  11. pcapkit/corekit/protochain.py +8 -1
  12. pcapkit/foundation/registry/protocols.py +108 -16
  13. pcapkit/protocols/data/__init__.py +4 -4
  14. pcapkit/protocols/data/internet/__init__.py +4 -4
  15. pcapkit/protocols/data/internet/mh.py +8 -6
  16. pcapkit/protocols/data/transport/__init__.py +4 -4
  17. pcapkit/protocols/data/transport/tcp.py +4 -4
  18. pcapkit/protocols/internet/mh.py +21 -21
  19. pcapkit/protocols/protocol.py +3 -2
  20. pcapkit/protocols/schema/__init__.py +4 -4
  21. pcapkit/protocols/schema/application/httpv2.py +17 -33
  22. pcapkit/protocols/schema/internet/__init__.py +4 -4
  23. pcapkit/protocols/schema/internet/hip.py +62 -111
  24. pcapkit/protocols/schema/internet/hopopt.py +46 -48
  25. pcapkit/protocols/schema/internet/ipv4.py +36 -41
  26. pcapkit/protocols/schema/internet/ipv6_opts.py +48 -52
  27. pcapkit/protocols/schema/internet/ipv6_route.py +12 -21
  28. pcapkit/protocols/schema/internet/mh.py +57 -86
  29. pcapkit/protocols/schema/misc/pcapng.py +182 -193
  30. pcapkit/protocols/schema/schema.py +252 -53
  31. pcapkit/protocols/schema/transport/__init__.py +4 -4
  32. pcapkit/protocols/schema/transport/tcp.py +54 -81
  33. pcapkit/protocols/transport/tcp.py +14 -14
  34. pcapkit/vendor/pcapng/option_type.py +29 -2
  35. pcapkit/vendor/reg/apptype.py +34 -4
  36. {pypcapkit-1.0.3.dist-info → pypcapkit-1.1.0.dist-info}/METADATA +1 -1
  37. {pypcapkit-1.0.3.dist-info → pypcapkit-1.1.0.dist-info}/RECORD +41 -41
  38. {pypcapkit-1.0.3.dist-info → pypcapkit-1.1.0.dist-info}/LICENSE +0 -0
  39. {pypcapkit-1.0.3.dist-info → pypcapkit-1.1.0.dist-info}/WHEEL +0 -0
  40. {pypcapkit-1.0.3.dist-info → pypcapkit-1.1.0.dist-info}/entry_points.txt +0 -0
  41. {pypcapkit-1.0.3.dist-info → pypcapkit-1.1.0.dist-info}/top_level.txt +0 -0
@@ -4,6 +4,7 @@
4
4
 
5
5
  import base64
6
6
  import collections
7
+ import collections.abc
7
8
  import io
8
9
  import struct
9
10
  import sys
@@ -25,7 +26,7 @@ from pcapkit.corekit.fields.numbers import (EnumField, Int32Field, Int64Field, N
25
26
  UInt8Field, UInt16Field, UInt32Field, UInt64Field)
26
27
  from pcapkit.corekit.fields.strings import BitField, BytesField, PaddingField, StringField
27
28
  from pcapkit.corekit.multidict import MultiDict, OrderedMultiDict
28
- from pcapkit.protocols.schema.schema import Schema, schema_final
29
+ from pcapkit.protocols.schema.schema import EnumSchema, Schema, schema_final
29
30
  from pcapkit.utilities.exceptions import FieldValueError, ProtocolError, stacklevel
30
31
  from pcapkit.utilities.logging import SPHINX_TYPE_CHECKING
31
32
  from pcapkit.utilities.warnings import ProtocolWarning, warn
@@ -60,7 +61,7 @@ __all__ = [
60
61
 
61
62
  if TYPE_CHECKING:
62
63
  from ipaddress import IPv4Address, IPv4Interface, IPv6Address, IPv6Interface
63
- from typing import Any, Callable, Optional
64
+ from typing import Any, Callable, DefaultDict, Iterable, Optional, Type
64
65
 
65
66
  from typing_extensions import Literal, Self
66
67
 
@@ -190,31 +191,14 @@ def pcapng_block_selector(packet: 'dict[str, Any]') -> 'Field':
190
191
  wrapped :class:`~pcapkit.protocols.schema.misc.pcapng.BlockType`
191
192
  subclass instance.
192
193
 
194
+ See Also:
195
+ * :class:`pcapkit.const.pcapng.block_type.BlockType`
196
+ * :class:`pcapkit.protocols.schema.misc.pcapng.BlockType`
197
+
193
198
  """
194
199
  block_type = packet['type'] # type: Enum_BlockType
195
- if block_type == Enum_BlockType.Section_Header_Block:
196
- return SchemaField(length=packet['__length__'], schema=SectionHeaderBlock)
197
- elif block_type == Enum_BlockType.Interface_Description_Block:
198
- return SchemaField(length=packet['__length__'], schema=InterfaceDescriptionBlock)
199
- elif block_type == Enum_BlockType.Enhanced_Packet_Block:
200
- return SchemaField(length=packet['__length__'], schema=EnhancedPacketBlock)
201
- elif block_type == Enum_BlockType.Simple_Packet_Block:
202
- return SchemaField(length=packet['__length__'], schema=SimplePacketBlock)
203
- elif block_type == Enum_BlockType.Name_Resolution_Block:
204
- return SchemaField(length=packet['__length__'], schema=NameResolutionBlock)
205
- elif block_type == Enum_BlockType.Interface_Statistics_Block:
206
- return SchemaField(length=packet['__length__'], schema=InterfaceStatisticsBlock)
207
- elif block_type == Enum_BlockType.systemd_Journal_Export_Block:
208
- return SchemaField(length=packet['__length__'], schema=SystemdJournalExportBlock)
209
- elif block_type == Enum_BlockType.Decryption_Secrets_Block:
210
- return SchemaField(length=packet['__length__'], schema=DecryptionSecretsBlock)
211
- elif block_type == Enum_BlockType.Custom_Block_that_rewriters_can_copy_into_new_files:
212
- return SchemaField(length=packet['__length__'], schema=CustomBlock)
213
- elif block_type == Enum_BlockType.Custom_Block_that_rewriters_should_not_copy_into_new_files:
214
- return SchemaField(length=packet['__length__'], schema=CustomBlock)
215
- elif block_type == Enum_BlockType.Packet_Block:
216
- return SchemaField(length=packet['__length__'], schema=PacketBlock)
217
- return SchemaField(length=packet['__length__'], schema=UnknownBlock)
200
+ schema = BlockType.registry[block_type]
201
+ return SchemaField(length=packet['__length__'], schema=schema)
218
202
 
219
203
 
220
204
  def dsb_secrets_selector(packet: 'dict[str, Any]') -> 'Field':
@@ -233,17 +217,14 @@ def dsb_secrets_selector(packet: 'dict[str, Any]') -> 'Field':
233
217
  wrapped :class:`~pcapkit.protocols.schema.misc.pcapng.DSBSecrets`
234
218
  subclass instance.
235
219
 
220
+ See Also:
221
+ * :class:`pcapkit.const.pcapng.secrets_type.Secrets_Type`
222
+ * :class:`pcapkit.protocols.schema.misc.pcapng.DSBSecrets`
223
+
236
224
  """
237
225
  secrets_type = packet['secrets_type'] # type: int
238
- if secrets_type == Enum_SecretsType.TLS_Key_Log:
239
- return SchemaField(length=packet['secrets_length'], schema=TLSKeyLog)
240
- if secrets_type == Enum_SecretsType.WireGuard_Key_Log:
241
- return SchemaField(length=packet['secrets_length'], schema=WireGuardKeyLog)
242
- if secrets_type == Enum_SecretsType.ZigBee_NWK_Key:
243
- return SchemaField(length=packet['secrets_length'], schema=ZigBeeNWKKey)
244
- if secrets_type == Enum_SecretsType.ZigBee_APS_Key:
245
- return SchemaField(length=packet['secrets_length'], schema=ZigBeeAPSKey)
246
- return SchemaField(length=packet['secrets_length'], schema=UnknownSecrets)
226
+ schema = DSBSecrets.registry[secrets_type]
227
+ return SchemaField(length=packet['secrets_length'], schema=schema)
247
228
 
248
229
 
249
230
  class OptionEnumField(EnumField):
@@ -323,9 +304,11 @@ class PCAPNG(Schema):
323
304
  def __init__(self, type: 'Enum_BlockType', block: 'BlockType | bytes') -> 'None': ...
324
305
 
325
306
 
326
- class BlockType(Schema):
307
+ class BlockType(EnumSchema[Enum_BlockType]):
327
308
  """Header schema for PCAP-NG file blocks."""
328
309
 
310
+ __default__ = lambda: UnknownBlock
311
+
329
312
  def post_process(self, packet: 'dict[str, Any]') -> 'Schema':
330
313
  """Revise ``schema`` data after unpacking process.
331
314
 
@@ -367,9 +350,94 @@ class UnknownBlock(BlockType):
367
350
  def __init__(self, length: 'int', body: 'bytes', length2: 'int') -> 'None': ...
368
351
 
369
352
 
370
- class Option(Schema):
353
+ class Option(EnumSchema[Enum_OptionType]):
371
354
  """Header schema for PCAP-NG file options."""
372
355
 
356
+ __additional__ = ['__enum__', '__namespace__']
357
+ __excluded__ = ['__enum__', '__namespace__']
358
+
359
+ #: Namespace of PCAP-NG option type numbers.
360
+ __namespace__: 'str' = None # type: ignore[assignment]
361
+ #: Mapping of PCAP-NG option type numbers to schemas.
362
+ __enum__: 'DefaultDict[str, DefaultDict[Enum_OptionType, Type[Option]]]' = collections.defaultdict(
363
+ lambda: Option.registry['opt'], {
364
+ 'opt': collections.defaultdict(lambda: UnknownOption),
365
+ 'if': collections.defaultdict(lambda: UnknownOption),
366
+ 'epb': collections.defaultdict(lambda: UnknownOption),
367
+ 'ns': collections.defaultdict(lambda: UnknownOption),
368
+ 'isb': collections.defaultdict(lambda: UnknownOption),
369
+ 'dsb': collections.defaultdict(lambda: UnknownOption),
370
+ 'pack': collections.defaultdict(lambda: UnknownOption),
371
+ },
372
+ )
373
+
374
+ def __init_subclass__(cls, /, code: 'Optional[Enum_OptionType | Iterable[Enum_OptionType]]' = None,
375
+ namespace: 'Optional[str]' = None, *args: 'Any', **kwargs: 'Any') -> 'None':
376
+ """Register option type to :attr:`__enum__` mapping.
377
+
378
+ Args:
379
+ code: Option type code. It can be either a single option type enumeration
380
+ or a list of option type enumerations.
381
+ namespace: Namespace of option type enumeration. If not given, the value
382
+ will be inferred from the option type code.
383
+ *args: Arbitrary positional arguments.
384
+ **kwargs: Arbitrary keyword arguments.
385
+
386
+ If ``code`` is provided, the subclass will be registered to the
387
+ :attr:`__enum__` mapping with the given ``code``. If ``code`` is
388
+ not given, the subclass will not be registered.
389
+
390
+ Examples:
391
+
392
+ .. code-block:: python
393
+
394
+ from pcapkit.const.pcapng.option_type import OptionType as Enum_OptionType
395
+ from pcapkit.protocols.schema.misc.pcapng improt Option
396
+
397
+ class NewOption(Option, namespace='opt', code=Enum_OptionType.opt_new):
398
+ ...
399
+
400
+ See Also:
401
+ - :class:`pcapkit.const.pcapng.option_type.OptionType`
402
+
403
+ """
404
+ if namespace is not None:
405
+ cls.__namespace__ = namespace
406
+
407
+ if code is not None:
408
+ if namespace is None:
409
+ namespace = cast('Optional[str]', cls.__namespace__)
410
+
411
+ if not isinstance(code, Enum_OptionType):
412
+ for _code in code:
413
+ Option.register(_code, cls, namespace)
414
+ else:
415
+ Option.register(code, cls, namespace)
416
+ super().__init_subclass__()
417
+
418
+ @staticmethod
419
+ def register(code: 'Enum_OptionType', cls: 'Type[Option]', ns: 'Optional[str]' = None) -> 'None':
420
+ """Register option type to :attr:`__enum__` mapping.
421
+
422
+ Args:
423
+ code: Option type code.
424
+ cls: Option type schema.
425
+ ns: Namespace of option type enumeration. If not given, the value
426
+ will be inferred from the option type code.
427
+
428
+ """
429
+ if ns is None:
430
+ ns = code.name.split('_')[0]
431
+
432
+ if ns == 'opt':
433
+ for key in Option.registry:
434
+ Option.registry[key][code] = cls
435
+ elif ns in Option.registry:
436
+ Option.registry[ns][code] = cls
437
+ else:
438
+ Option.registry[ns] = Option.registry['opt'].copy()
439
+ Option.registry[ns][code] = cls
440
+
373
441
  if TYPE_CHECKING:
374
442
  #: Option type.
375
443
  type: 'Enum_OptionType'
@@ -377,7 +445,7 @@ class Option(Schema):
377
445
  length: 'int'
378
446
 
379
447
 
380
- class _OPT_Option(Option):
448
+ class _OPT_Option(Option, namespace='opt'):
381
449
  """Header schema for ``opt_*`` options."""
382
450
 
383
451
  #: Option type.
@@ -400,7 +468,7 @@ class UnknownOption(_OPT_Option):
400
468
 
401
469
 
402
470
  @schema_final
403
- class EndOfOption(_OPT_Option):
471
+ class EndOfOption(_OPT_Option, code=Enum_OptionType.opt_endofopt):
404
472
  """Header schema for PCAP-NG file ``opt_endofopt`` options."""
405
473
 
406
474
  if TYPE_CHECKING:
@@ -408,7 +476,7 @@ class EndOfOption(_OPT_Option):
408
476
 
409
477
 
410
478
  @schema_final
411
- class CommentOption(_OPT_Option):
479
+ class CommentOption(_OPT_Option, code=Enum_OptionType.opt_comment):
412
480
  """Header schema for PCAP-NG file ``opt_comment`` options."""
413
481
 
414
482
  #: Comment text.
@@ -421,7 +489,10 @@ class CommentOption(_OPT_Option):
421
489
 
422
490
 
423
491
  @schema_final
424
- class CustomOption(_OPT_Option):
492
+ class CustomOption(_OPT_Option, code=[Enum_OptionType.opt_custom_2988,
493
+ Enum_OptionType.opt_custom_2989,
494
+ Enum_OptionType.opt_custom_19372,
495
+ Enum_OptionType.opt_custom_19373]):
425
496
  """Header schema for PCAP-NG file ``opt_custom`` options."""
426
497
 
427
498
  #: Private enterprise number (PEN).
@@ -436,7 +507,7 @@ class CustomOption(_OPT_Option):
436
507
 
437
508
 
438
509
  @schema_final
439
- class SectionHeaderBlock(BlockType):
510
+ class SectionHeaderBlock(BlockType, code=Enum_BlockType.Section_Header_Block):
440
511
  """Header schema for PCAP-NG Section Header Block (SHB)."""
441
512
 
442
513
  #: Fast forward field to test the byteorder.
@@ -458,14 +529,7 @@ class SectionHeaderBlock(BlockType):
458
529
  length=lambda pkt: pkt['length'] - 28,
459
530
  base_schema=_OPT_Option,
460
531
  type_name='type',
461
- registry=collections.defaultdict(lambda: UnknownOption, {
462
- Enum_OptionType.opt_endofopt: EndOfOption,
463
- Enum_OptionType.opt_comment: CommentOption,
464
- Enum_OptionType.opt_custom_2988: CustomOption,
465
- Enum_OptionType.opt_custom_2989: CustomOption,
466
- Enum_OptionType.opt_custom_19372: CustomOption,
467
- Enum_OptionType.opt_custom_19373: CustomOption,
468
- }),
532
+ registry=Option.registry['opt'],
469
533
  eool=Enum_OptionType.opt_endofopt,
470
534
  )
471
535
  #: Padding.
@@ -527,7 +591,7 @@ class SectionHeaderBlock(BlockType):
527
591
  length2: 'int') -> 'None': ...
528
592
 
529
593
 
530
- class _IF_Option(Option):
594
+ class _IF_Option(Option, namespace='if'):
531
595
  """Header schema for ``if_*`` options."""
532
596
 
533
597
  #: Option type.
@@ -537,7 +601,7 @@ class _IF_Option(Option):
537
601
 
538
602
 
539
603
  @schema_final
540
- class IF_NameOption(_IF_Option):
604
+ class IF_NameOption(_IF_Option, code=Enum_OptionType.if_name):
541
605
  """Header schema for PCAP-NG file ``if_name`` options."""
542
606
 
543
607
  #: Interface name.
@@ -550,7 +614,7 @@ class IF_NameOption(_IF_Option):
550
614
 
551
615
 
552
616
  @schema_final
553
- class IF_DescriptionOption(_IF_Option):
617
+ class IF_DescriptionOption(_IF_Option, code=Enum_OptionType.if_description):
554
618
  """Header schema for PCAP-NG file ``if_description`` options."""
555
619
 
556
620
  #: Interface description.
@@ -563,7 +627,7 @@ class IF_DescriptionOption(_IF_Option):
563
627
 
564
628
 
565
629
  @schema_final
566
- class IF_IPv4AddrOption(_IF_Option):
630
+ class IF_IPv4AddrOption(_IF_Option, code=Enum_OptionType.if_IPv4addr):
567
631
  """Header schema for PCAP-NG file ``if_IPv4addr`` options."""
568
632
 
569
633
  #: IPv4 interface.
@@ -576,7 +640,7 @@ class IF_IPv4AddrOption(_IF_Option):
576
640
 
577
641
 
578
642
  @schema_final
579
- class IF_IPv6AddrOption(_IF_Option):
643
+ class IF_IPv6AddrOption(_IF_Option, code=Enum_OptionType.if_IPv6addr):
580
644
  """Header schema for PCAP-NG file ``if_IPv6addr`` options."""
581
645
 
582
646
  #: IPv6 interface.
@@ -589,7 +653,7 @@ class IF_IPv6AddrOption(_IF_Option):
589
653
 
590
654
 
591
655
  @schema_final
592
- class IF_MACAddrOption(_IF_Option):
656
+ class IF_MACAddrOption(_IF_Option, code=Enum_OptionType.if_MACaddr):
593
657
  """Header schema for PCAP-NG file ``if_MACaddr`` options."""
594
658
 
595
659
  #: MAC interface.
@@ -602,7 +666,7 @@ class IF_MACAddrOption(_IF_Option):
602
666
 
603
667
 
604
668
  @schema_final
605
- class IF_EUIAddrOption(_IF_Option):
669
+ class IF_EUIAddrOption(_IF_Option, code=Enum_OptionType.if_EUIaddr):
606
670
  """Header schema for PCAP-NG file ``if_EUIaddr`` options."""
607
671
 
608
672
  #: EUI interface.
@@ -615,7 +679,7 @@ class IF_EUIAddrOption(_IF_Option):
615
679
 
616
680
 
617
681
  @schema_final
618
- class IF_SpeedOption(_IF_Option):
682
+ class IF_SpeedOption(_IF_Option, code=Enum_OptionType.if_speed):
619
683
  """Header schema for PCAP-NG file ``if_speed`` options."""
620
684
 
621
685
  #: Interface speed, in bits per second.
@@ -628,7 +692,7 @@ class IF_SpeedOption(_IF_Option):
628
692
 
629
693
 
630
694
  @schema_final
631
- class IF_TSResolOption(_IF_Option):
695
+ class IF_TSResolOption(_IF_Option, code=Enum_OptionType.if_tsresol):
632
696
  """Header schema for PCAP-NG file ``if_tsresol`` options."""
633
697
 
634
698
  #: Interface timestamp resolution, in units per second.
@@ -661,7 +725,7 @@ class IF_TSResolOption(_IF_Option):
661
725
 
662
726
 
663
727
  @schema_final
664
- class IF_TZoneOption(_IF_Option):
728
+ class IF_TZoneOption(_IF_Option, code=Enum_OptionType.if_tzone):
665
729
  """Header schema for PCAP-NG file ``if_tzone`` options."""
666
730
 
667
731
  #: Interface time zone (as in seconds difference from GMT).
@@ -674,7 +738,7 @@ class IF_TZoneOption(_IF_Option):
674
738
 
675
739
 
676
740
  @schema_final
677
- class IF_FilterOption(_IF_Option):
741
+ class IF_FilterOption(_IF_Option, code=Enum_OptionType.if_filter):
678
742
  """Header schema for PCAP-NG file ``if_filter`` options."""
679
743
 
680
744
  #: Filter code.
@@ -689,7 +753,7 @@ class IF_FilterOption(_IF_Option):
689
753
 
690
754
 
691
755
  @schema_final
692
- class IF_OSOption(_IF_Option):
756
+ class IF_OSOption(_IF_Option, code=Enum_OptionType.if_os):
693
757
  """Header schema for PCAP-NG file ``if_os`` options."""
694
758
 
695
759
  #: OS information.
@@ -702,7 +766,7 @@ class IF_OSOption(_IF_Option):
702
766
 
703
767
 
704
768
  @schema_final
705
- class IF_FCSLenOption(_IF_Option):
769
+ class IF_FCSLenOption(_IF_Option, code=Enum_OptionType.if_fcslen):
706
770
  """Header schema for PCAP-NG file ``if_fcslen`` options."""
707
771
 
708
772
  #: FCS length.
@@ -715,7 +779,7 @@ class IF_FCSLenOption(_IF_Option):
715
779
 
716
780
 
717
781
  @schema_final
718
- class IF_TSOffsetOption(_IF_Option):
782
+ class IF_TSOffsetOption(_IF_Option, code=Enum_OptionType.if_tsoffset):
719
783
  """Header schema for PCAP-NG file ``if_tsoffset`` options."""
720
784
 
721
785
  #: Timestamp offset (in seconds).
@@ -728,7 +792,7 @@ class IF_TSOffsetOption(_IF_Option):
728
792
 
729
793
 
730
794
  @schema_final
731
- class IF_HardwareOption(_IF_Option):
795
+ class IF_HardwareOption(_IF_Option, code=Enum_OptionType.if_hardware):
732
796
  """Header schema for PCAP-NG file ``if_hardware`` options."""
733
797
 
734
798
  #: Hardware information.
@@ -741,7 +805,7 @@ class IF_HardwareOption(_IF_Option):
741
805
 
742
806
 
743
807
  @schema_final
744
- class IF_TxSpeedOption(_IF_Option):
808
+ class IF_TxSpeedOption(_IF_Option, code=Enum_OptionType.if_txspeed):
745
809
  """Header schema for PCAP-NG file ``if_txspeed`` options."""
746
810
 
747
811
  #: Interface transmit speed, in bits per second.
@@ -754,7 +818,7 @@ class IF_TxSpeedOption(_IF_Option):
754
818
 
755
819
 
756
820
  @schema_final
757
- class IF_RxSpeedOption(_IF_Option):
821
+ class IF_RxSpeedOption(_IF_Option, code=Enum_OptionType.if_rxspeed):
758
822
  """Header schema for PCAP-NG file ``if_rxspeed`` options."""
759
823
 
760
824
  #: Interface receive speed, in bits per second.
@@ -767,7 +831,7 @@ class IF_RxSpeedOption(_IF_Option):
767
831
 
768
832
 
769
833
  @schema_final
770
- class InterfaceDescriptionBlock(BlockType):
834
+ class InterfaceDescriptionBlock(BlockType, code=Enum_BlockType.Interface_Description_Block):
771
835
  """Header schema for PCAP-NG Interface Description Block (IDB)."""
772
836
 
773
837
  #: Block total length.
@@ -783,30 +847,7 @@ class InterfaceDescriptionBlock(BlockType):
783
847
  length=lambda pkt: pkt['length'] - 20,
784
848
  base_schema=_IF_Option,
785
849
  type_name='type',
786
- registry=collections.defaultdict(lambda: UnknownOption, {
787
- Enum_OptionType.opt_endofopt: EndOfOption,
788
- Enum_OptionType.opt_comment: CommentOption,
789
- Enum_OptionType.opt_custom_2988: CustomOption,
790
- Enum_OptionType.opt_custom_2989: CustomOption,
791
- Enum_OptionType.opt_custom_19372: CustomOption,
792
- Enum_OptionType.opt_custom_19373: CustomOption,
793
- Enum_OptionType.if_name: IF_NameOption,
794
- Enum_OptionType.if_description: IF_DescriptionOption,
795
- Enum_OptionType.if_IPv4addr: IF_IPv4AddrOption,
796
- Enum_OptionType.if_IPv6addr: IF_IPv6AddrOption,
797
- Enum_OptionType.if_MACaddr: IF_MACAddrOption,
798
- Enum_OptionType.if_EUIaddr: IF_EUIAddrOption,
799
- Enum_OptionType.if_speed: IF_SpeedOption,
800
- Enum_OptionType.if_tsresol: IF_TSResolOption,
801
- Enum_OptionType.if_tzone: IF_TZoneOption,
802
- Enum_OptionType.if_filter: IF_FilterOption,
803
- Enum_OptionType.if_os: IF_OSOption,
804
- Enum_OptionType.if_fcslen: IF_FCSLenOption,
805
- Enum_OptionType.if_tsoffset: IF_TSOffsetOption,
806
- Enum_OptionType.if_hardware: IF_HardwareOption,
807
- Enum_OptionType.if_txspeed: IF_TxSpeedOption,
808
- Enum_OptionType.if_rxspeed: IF_RxSpeedOption,
809
- }),
850
+ registry=Option.registry['if'],
810
851
  eool=Enum_OptionType.opt_endofopt,
811
852
  )
812
853
  #: Padding.
@@ -819,7 +860,7 @@ class InterfaceDescriptionBlock(BlockType):
819
860
  options: 'list[Option | bytes] | bytes', length2: 'int') -> 'None': ...
820
861
 
821
862
 
822
- class _EPB_Option(Option):
863
+ class _EPB_Option(Option, namespace='epb'):
823
864
  """Header schema for ``epb_*`` options."""
824
865
 
825
866
  #: Option type.
@@ -829,7 +870,7 @@ class _EPB_Option(Option):
829
870
 
830
871
 
831
872
  @schema_final
832
- class EPB_FlagsOption(_EPB_Option):
873
+ class EPB_FlagsOption(_EPB_Option, code=Enum_OptionType.epb_flags):
833
874
  """Header schema for PCAP-NG ``epb_flags`` options."""
834
875
 
835
876
  #: Flags.
@@ -854,7 +895,7 @@ class EPB_FlagsOption(_EPB_Option):
854
895
 
855
896
 
856
897
  @schema_final
857
- class EPB_HashOption(_EPB_Option):
898
+ class EPB_HashOption(_EPB_Option, code=Enum_OptionType.epb_hash):
858
899
  """Header schema for PCAP-NG ``epb_hash`` options."""
859
900
 
860
901
  #: Hash algorithm.
@@ -869,7 +910,7 @@ class EPB_HashOption(_EPB_Option):
869
910
 
870
911
 
871
912
  @schema_final
872
- class EPB_DropCountOption(_EPB_Option):
913
+ class EPB_DropCountOption(_EPB_Option, code=Enum_OptionType.epb_dropcount):
873
914
  """Header schema for PCAP-NG ``epb_dropcount`` options."""
874
915
 
875
916
  #: Number of packets dropped by the interface.
@@ -882,7 +923,7 @@ class EPB_DropCountOption(_EPB_Option):
882
923
 
883
924
 
884
925
  @schema_final
885
- class EPB_PacketIDOption(_EPB_Option):
926
+ class EPB_PacketIDOption(_EPB_Option, code=Enum_OptionType.epb_packetid):
886
927
  """Header schema for PCAP-NG ``epb_packetid`` options."""
887
928
 
888
929
  #: Packet ID.
@@ -895,7 +936,7 @@ class EPB_PacketIDOption(_EPB_Option):
895
936
 
896
937
 
897
938
  @schema_final
898
- class EPB_QueueOption(_EPB_Option):
939
+ class EPB_QueueOption(_EPB_Option, code=Enum_OptionType.epb_queue):
899
940
  """Header schema for PCAP-NG ``epb_queue`` options."""
900
941
 
901
942
  #: Queue ID.
@@ -908,7 +949,7 @@ class EPB_QueueOption(_EPB_Option):
908
949
 
909
950
 
910
951
  @schema_final
911
- class EPB_VerdictOption(_EPB_Option):
952
+ class EPB_VerdictOption(_EPB_Option, code=Enum_OptionType.epb_verdict):
912
953
  """Header schema for PCAP-NG ``epb_verdict`` options."""
913
954
 
914
955
  #: Verdict type.
@@ -923,7 +964,7 @@ class EPB_VerdictOption(_EPB_Option):
923
964
 
924
965
 
925
966
  @schema_final
926
- class EnhancedPacketBlock(BlockType):
967
+ class EnhancedPacketBlock(BlockType, code=Enum_BlockType.Enhanced_Packet_Block):
927
968
  """Header schema for PCAP-NG Enhanced Packet Block (EPB)."""
928
969
 
929
970
  __payload__ = 'packet_data'
@@ -949,20 +990,7 @@ class EnhancedPacketBlock(BlockType):
949
990
  length=lambda pkt: pkt['length'] - 32 - pkt['captured_len'] - len(pkt['padding_data']),
950
991
  base_schema=_EPB_Option,
951
992
  type_name='type',
952
- registry=collections.defaultdict(lambda: UnknownOption, {
953
- Enum_OptionType.opt_endofopt: EndOfOption,
954
- Enum_OptionType.opt_comment: CommentOption,
955
- Enum_OptionType.opt_custom_2988: CustomOption,
956
- Enum_OptionType.opt_custom_2989: CustomOption,
957
- Enum_OptionType.opt_custom_19372: CustomOption,
958
- Enum_OptionType.opt_custom_19373: CustomOption,
959
- Enum_OptionType.epb_flags: EPB_FlagsOption,
960
- Enum_OptionType.epb_hash: EPB_HashOption,
961
- Enum_OptionType.epb_dropcount: EPB_DropCountOption,
962
- Enum_OptionType.epb_packetid: EPB_PacketIDOption,
963
- Enum_OptionType.epb_queue: EPB_QueueOption,
964
- Enum_OptionType.epb_verdict: EPB_VerdictOption,
965
- }),
993
+ registry=Option.registry['epb'],
966
994
  eool=Enum_OptionType.opt_endofopt,
967
995
  )
968
996
  #: Padding.
@@ -978,7 +1006,7 @@ class EnhancedPacketBlock(BlockType):
978
1006
 
979
1007
 
980
1008
  @schema_final
981
- class SimplePacketBlock(BlockType):
1009
+ class SimplePacketBlock(BlockType, code=Enum_BlockType.Simple_Packet_Block):
982
1010
  """Header schema for PCAP-NG Simple Packet Block (SPB)."""
983
1011
 
984
1012
  __payload__ = 'packet_data'
@@ -1001,9 +1029,11 @@ class SimplePacketBlock(BlockType):
1001
1029
  length2: 'int') -> 'None': ...
1002
1030
 
1003
1031
 
1004
- class NameResolutionRecord(Schema):
1032
+ class NameResolutionRecord(EnumSchema[Enum_RecordType]):
1005
1033
  """Header schema for PCAP-NG NRB records."""
1006
1034
 
1035
+ __default__ = lambda: UnknownRecord
1036
+
1007
1037
  #: Record type.
1008
1038
  type: 'Enum_RecordType' = EnumField(length=2, namespace=Enum_RecordType, callback=byteorder_callback)
1009
1039
  #: Record value length.
@@ -1024,7 +1054,7 @@ class UnknownRecord(NameResolutionRecord):
1024
1054
 
1025
1055
 
1026
1056
  @schema_final
1027
- class EndRecord(NameResolutionRecord):
1057
+ class EndRecord(NameResolutionRecord, code=Enum_RecordType.nrb_record_end):
1028
1058
  """Header schema for PCAP-NG ``nrb_record_end`` records."""
1029
1059
 
1030
1060
  if TYPE_CHECKING:
@@ -1032,7 +1062,7 @@ class EndRecord(NameResolutionRecord):
1032
1062
 
1033
1063
 
1034
1064
  @schema_final
1035
- class IPv4Record(NameResolutionRecord):
1065
+ class IPv4Record(NameResolutionRecord, code=Enum_RecordType.nrb_record_ipv4):
1036
1066
  """Header schema for PCAP-NG NRB ``nrb_record_ipv4`` records."""
1037
1067
 
1038
1068
  #: IPv4 address.
@@ -1063,7 +1093,7 @@ class IPv4Record(NameResolutionRecord):
1063
1093
 
1064
1094
 
1065
1095
  @schema_final
1066
- class IPv6Record(NameResolutionRecord):
1096
+ class IPv6Record(NameResolutionRecord, code=Enum_RecordType.nrb_record_ipv6):
1067
1097
  """Header schema for PCAP-NG NRB ``nrb_record_ipv4`` records."""
1068
1098
 
1069
1099
  #: IPv4 address.
@@ -1093,7 +1123,7 @@ class IPv6Record(NameResolutionRecord):
1093
1123
  def __init__(self, type: 'Enum_RecordType', length: 'int', ip: 'IPv6Address | str | bytes | int', resol: 'str') -> 'None': ...
1094
1124
 
1095
1125
 
1096
- class _NS_Option(Option):
1126
+ class _NS_Option(Option, namespace='ns'):
1097
1127
  """Header schema for ``ns_*`` options."""
1098
1128
 
1099
1129
  #: Option type.
@@ -1103,7 +1133,7 @@ class _NS_Option(Option):
1103
1133
 
1104
1134
 
1105
1135
  @schema_final
1106
- class NS_DNSNameOption(_NS_Option):
1136
+ class NS_DNSNameOption(_NS_Option, code=Enum_OptionType.ns_dnsname):
1107
1137
  """Header schema for PCAP-NG ``ns_dnsname`` option."""
1108
1138
 
1109
1139
  #: DNS name.
@@ -1114,7 +1144,7 @@ class NS_DNSNameOption(_NS_Option):
1114
1144
 
1115
1145
 
1116
1146
  @schema_final
1117
- class NS_DNSIP4AddrOption(_NS_Option):
1147
+ class NS_DNSIP4AddrOption(_NS_Option, code=Enum_OptionType.ns_dnsIP4addr):
1118
1148
  """Header schema for PCAP-NG ``ns_dnsIP4addr`` option."""
1119
1149
 
1120
1150
  #: IPv4 address.
@@ -1125,7 +1155,7 @@ class NS_DNSIP4AddrOption(_NS_Option):
1125
1155
 
1126
1156
 
1127
1157
  @schema_final
1128
- class NS_DNSIP6AddrOption(_NS_Option):
1158
+ class NS_DNSIP6AddrOption(_NS_Option, code=Enum_OptionType.ns_dnsIP6addr):
1129
1159
  """Header schema for PCAP-NG ``ns_dnsIP6addr`` option."""
1130
1160
 
1131
1161
  #: IPv6 address.
@@ -1136,7 +1166,7 @@ class NS_DNSIP6AddrOption(_NS_Option):
1136
1166
 
1137
1167
 
1138
1168
  @schema_final
1139
- class NameResolutionBlock(BlockType):
1169
+ class NameResolutionBlock(BlockType, code=Enum_BlockType.Name_Resolution_Block):
1140
1170
  """Header schema for PCAP-NG Name Resolution Block (NRB)."""
1141
1171
 
1142
1172
  #: Record total length.
@@ -1146,11 +1176,7 @@ class NameResolutionBlock(BlockType):
1146
1176
  length=lambda pkt: pkt['length'] - 12,
1147
1177
  base_schema=NameResolutionRecord,
1148
1178
  type_name='type',
1149
- registry=collections.defaultdict(lambda: UnknownRecord, {
1150
- Enum_RecordType.nrb_record_end: EndRecord,
1151
- Enum_RecordType.nrb_record_ipv4: IPv4Record,
1152
- Enum_RecordType.nrb_record_ipv6: IPv6Record,
1153
- }),
1179
+ registry=NameResolutionRecord.registry,
1154
1180
  eool=Enum_RecordType.nrb_record_end,
1155
1181
  )
1156
1182
  #: Options.
@@ -1158,17 +1184,7 @@ class NameResolutionBlock(BlockType):
1158
1184
  length=lambda pkt: pkt['__option_padding__'] - 4 if pkt['__option_padding__'] else 0,
1159
1185
  base_schema=_NS_Option,
1160
1186
  type_name='type',
1161
- registry=collections.defaultdict(lambda: UnknownOption, {
1162
- Enum_OptionType.opt_endofopt: EndOfOption,
1163
- Enum_OptionType.opt_comment: CommentOption,
1164
- Enum_OptionType.opt_custom_2988: CustomOption,
1165
- Enum_OptionType.opt_custom_2989: CustomOption,
1166
- Enum_OptionType.opt_custom_19372: CustomOption,
1167
- Enum_OptionType.opt_custom_19373: CustomOption,
1168
- Enum_OptionType.ns_dnsname: NS_DNSNameOption,
1169
- Enum_OptionType.ns_dnsIP4addr: NS_DNSIP4AddrOption,
1170
- Enum_OptionType.ns_dnsIP6addr: NS_DNSIP6AddrOption,
1171
- }),
1187
+ registry=Option.registry['ns'],
1172
1188
  eool=Enum_OptionType.opt_endofopt,
1173
1189
  )
1174
1190
  #: Padding.
@@ -1212,7 +1228,7 @@ class NameResolutionBlock(BlockType):
1212
1228
  options: 'list[Option | bytes] | bytes', length2: 'int') -> 'None': ...
1213
1229
 
1214
1230
 
1215
- class _ISB_Option(Option):
1231
+ class _ISB_Option(Option, namespace='isb'):
1216
1232
  """Header schema for ``isb_*`` options."""
1217
1233
 
1218
1234
  #: Option type.
@@ -1222,7 +1238,7 @@ class _ISB_Option(Option):
1222
1238
 
1223
1239
 
1224
1240
  @schema_final
1225
- class ISB_StartTimeOption(_ISB_Option):
1241
+ class ISB_StartTimeOption(_ISB_Option, code=Enum_OptionType.isb_starttime):
1226
1242
  """Header schema for PCAP-NG ``isb_starttime`` option."""
1227
1243
 
1228
1244
  #: Timestamp (higher 32 bits).
@@ -1235,7 +1251,7 @@ class ISB_StartTimeOption(_ISB_Option):
1235
1251
 
1236
1252
 
1237
1253
  @schema_final
1238
- class ISB_EndTimeOption(_ISB_Option):
1254
+ class ISB_EndTimeOption(_ISB_Option, code=Enum_OptionType.isb_endtime):
1239
1255
  """Header schema for PCAP-NG ``isb_endtime`` option."""
1240
1256
 
1241
1257
  #: Timestamp (higher 32 bits).
@@ -1248,7 +1264,7 @@ class ISB_EndTimeOption(_ISB_Option):
1248
1264
 
1249
1265
 
1250
1266
  @schema_final
1251
- class ISB_IFRecvOption(_ISB_Option):
1267
+ class ISB_IFRecvOption(_ISB_Option, code=Enum_OptionType.isb_ifrecv):
1252
1268
  """Header schema for PCAP-NG ``isb_ifrecv`` option."""
1253
1269
 
1254
1270
  #: Number of packets received.
@@ -1259,7 +1275,7 @@ class ISB_IFRecvOption(_ISB_Option):
1259
1275
 
1260
1276
 
1261
1277
  @schema_final
1262
- class ISB_IFDropOption(_ISB_Option):
1278
+ class ISB_IFDropOption(_ISB_Option, code=Enum_OptionType.isb_ifdrop):
1263
1279
  """Header schema for PCAP-NG ``isb_ifdrop`` option."""
1264
1280
 
1265
1281
  #: Number of packets dropped.
@@ -1270,7 +1286,7 @@ class ISB_IFDropOption(_ISB_Option):
1270
1286
 
1271
1287
 
1272
1288
  @schema_final
1273
- class ISB_FilterAcceptOption(_ISB_Option):
1289
+ class ISB_FilterAcceptOption(_ISB_Option, code=Enum_OptionType.isb_filteraccept):
1274
1290
  """Header schema for PCAP-NG ``isb_filteraccept`` option."""
1275
1291
 
1276
1292
  #: Number of packets accepted by filter.
@@ -1281,7 +1297,7 @@ class ISB_FilterAcceptOption(_ISB_Option):
1281
1297
 
1282
1298
 
1283
1299
  @schema_final
1284
- class ISB_OSDropOption(_ISB_Option):
1300
+ class ISB_OSDropOption(_ISB_Option, code=Enum_OptionType.isb_osdrop):
1285
1301
  """Header schema for PCAP-NG ``isb_osdrop`` option."""
1286
1302
 
1287
1303
  #: Number of packets dropped by OS.
@@ -1292,7 +1308,7 @@ class ISB_OSDropOption(_ISB_Option):
1292
1308
 
1293
1309
 
1294
1310
  @schema_final
1295
- class ISB_UsrDelivOption(_ISB_Option):
1311
+ class ISB_UsrDelivOption(_ISB_Option, code=Enum_OptionType.isb_usrdeliv):
1296
1312
  """Header schema for PCAP-NG ``isb_usrdeliv`` option."""
1297
1313
 
1298
1314
  #: Number of packets delivered to user.
@@ -1319,21 +1335,7 @@ class InterfaceStatisticsBlock(BlockType):
1319
1335
  length=lambda pkt: pkt['length'] - 20,
1320
1336
  base_schema=_ISB_Option,
1321
1337
  type_name='type',
1322
- registry=collections.defaultdict(lambda: UnknownOption, {
1323
- Enum_OptionType.opt_endofopt: EndOfOption,
1324
- Enum_OptionType.opt_comment: CommentOption,
1325
- Enum_OptionType.opt_custom_2988: CustomOption,
1326
- Enum_OptionType.opt_custom_2989: CustomOption,
1327
- Enum_OptionType.opt_custom_19372: CustomOption,
1328
- Enum_OptionType.opt_custom_19373: CustomOption,
1329
- Enum_OptionType.isb_starttime: ISB_StartTimeOption,
1330
- Enum_OptionType.isb_endtime: ISB_EndTimeOption,
1331
- Enum_OptionType.isb_ifrecv: ISB_IFRecvOption,
1332
- Enum_OptionType.isb_ifdrop: ISB_IFDropOption,
1333
- Enum_OptionType.isb_filteraccept: ISB_FilterAcceptOption,
1334
- Enum_OptionType.isb_osdrop: ISB_OSDropOption,
1335
- Enum_OptionType.isb_usrdeliv: ISB_UsrDelivOption,
1336
- }),
1338
+ registry=Option.registry['isb'],
1337
1339
  eool=Enum_OptionType.opt_endofopt,
1338
1340
  )
1339
1341
  #: Padding.
@@ -1348,7 +1350,7 @@ class InterfaceStatisticsBlock(BlockType):
1348
1350
 
1349
1351
 
1350
1352
  @schema_final
1351
- class SystemdJournalExportBlock(BlockType):
1353
+ class SystemdJournalExportBlock(BlockType, code=Enum_BlockType.systemd_Journal_Export_Block):
1352
1354
  """Header schema for PCAP-NG :manpage:`systemd(1)` Journal Export Block."""
1353
1355
 
1354
1356
  #: Block total length.
@@ -1400,9 +1402,11 @@ class SystemdJournalExportBlock(BlockType):
1400
1402
  def __init__(self, length: 'int', entry: 'bytes', length2: 'int') -> 'None': ...
1401
1403
 
1402
1404
 
1403
- class DSBSecrets(Schema):
1405
+ class DSBSecrets(EnumSchema[Enum_SecretsType]):
1404
1406
  """Header schema for DSB secrets data."""
1405
1407
 
1408
+ __default__ = lambda: UnknownSecrets
1409
+
1406
1410
 
1407
1411
  @schema_final
1408
1412
  class UnknownSecrets(DSBSecrets):
@@ -1416,7 +1420,7 @@ class UnknownSecrets(DSBSecrets):
1416
1420
 
1417
1421
 
1418
1422
  @schema_final
1419
- class TLSKeyLog(DSBSecrets):
1423
+ class TLSKeyLog(DSBSecrets, code=Enum_SecretsType.TLS_Key_Log):
1420
1424
  """Header schema for TLS Key Log secrets data."""
1421
1425
 
1422
1426
  #: TLS key log data.
@@ -1455,7 +1459,7 @@ class TLSKeyLog(DSBSecrets):
1455
1459
 
1456
1460
 
1457
1461
  @schema_final
1458
- class WireGuardKeyLog(DSBSecrets):
1462
+ class WireGuardKeyLog(DSBSecrets, code=Enum_SecretsType.WireGuard_Key_Log):
1459
1463
  """Header schema for WireGuard Key Log secrets data."""
1460
1464
 
1461
1465
  #: WireGuard key log data.
@@ -1495,7 +1499,7 @@ class WireGuardKeyLog(DSBSecrets):
1495
1499
 
1496
1500
 
1497
1501
  @schema_final
1498
- class ZigBeeNWKKey(DSBSecrets):
1502
+ class ZigBeeNWKKey(DSBSecrets, code=Enum_SecretsType.ZigBee_NWK_Key):
1499
1503
  """Header schema for ZigBee NWK Key and ZigBee PANID secrets data."""
1500
1504
 
1501
1505
  #: AES-128 NKW key.
@@ -1510,7 +1514,7 @@ class ZigBeeNWKKey(DSBSecrets):
1510
1514
 
1511
1515
 
1512
1516
  @schema_final
1513
- class ZigBeeAPSKey(DSBSecrets):
1517
+ class ZigBeeAPSKey(DSBSecrets, code=Enum_SecretsType.ZigBee_APS_Key):
1514
1518
  """Header schema for ZigBee APS Key secrets data."""
1515
1519
 
1516
1520
  #: AES-128 APS key.
@@ -1528,7 +1532,7 @@ class ZigBeeAPSKey(DSBSecrets):
1528
1532
  def __init__(self, key: 'bytes', panid: 'int', addr_low: 'int', addr_high: 'int') -> 'None': ...
1529
1533
 
1530
1534
 
1531
- class _DSB_Option(Option):
1535
+ class _DSB_Option(Option, namespace='dsb'):
1532
1536
  """Header schema for ``dsb_*`` options."""
1533
1537
 
1534
1538
  #: Option type.
@@ -1538,7 +1542,7 @@ class _DSB_Option(Option):
1538
1542
 
1539
1543
 
1540
1544
  @schema_final
1541
- class DecryptionSecretsBlock(BlockType):
1545
+ class DecryptionSecretsBlock(BlockType, code=Enum_BlockType.Decryption_Secrets_Block):
1542
1546
  """Header schema for PCAP-NG Decryption Secrets Block (DSB)."""
1543
1547
 
1544
1548
  #: Block total length.
@@ -1558,14 +1562,7 @@ class DecryptionSecretsBlock(BlockType):
1558
1562
  length=lambda pkt: pkt['length'] - 20 - pkt['secrets_length'] - len(pkt['padding_data']),
1559
1563
  base_schema=_DSB_Option,
1560
1564
  type_name='type',
1561
- registry=collections.defaultdict(lambda: UnknownOption, {
1562
- Enum_OptionType.opt_endofopt: EndOfOption,
1563
- Enum_OptionType.opt_comment: CommentOption,
1564
- Enum_OptionType.opt_custom_2988: CustomOption,
1565
- Enum_OptionType.opt_custom_2989: CustomOption,
1566
- Enum_OptionType.opt_custom_19372: CustomOption,
1567
- Enum_OptionType.opt_custom_19373: CustomOption,
1568
- }),
1565
+ registry=Option.registry['dsb'],
1569
1566
  eool=Enum_OptionType.opt_endofopt,
1570
1567
  )
1571
1568
  #: Padding.
@@ -1580,7 +1577,8 @@ class DecryptionSecretsBlock(BlockType):
1580
1577
 
1581
1578
 
1582
1579
  @schema_final
1583
- class CustomBlock(BlockType):
1580
+ class CustomBlock(BlockType, code=[Enum_BlockType.Custom_Block_that_rewriters_can_copy_into_new_files,
1581
+ Enum_BlockType.Custom_Block_that_rewriters_should_not_copy_into_new_files]):
1584
1582
  """Header schema for PCAP-NG Custom Block (CB)."""
1585
1583
 
1586
1584
  #: Block total length.
@@ -1598,7 +1596,7 @@ class CustomBlock(BlockType):
1598
1596
  def __init__(self, length: 'int', pen: 'int', data: 'bytes', length2: 'int') -> 'None': ...
1599
1597
 
1600
1598
 
1601
- class _PACK_Option(Option):
1599
+ class _PACK_Option(Option, namespace='pack'):
1602
1600
  """Header schema for ``pack_*`` options."""
1603
1601
 
1604
1602
  #: Option type.
@@ -1608,7 +1606,7 @@ class _PACK_Option(Option):
1608
1606
 
1609
1607
 
1610
1608
  @schema_final
1611
- class PACK_FlagsOption(_PACK_Option):
1609
+ class PACK_FlagsOption(_PACK_Option, code=Enum_OptionType.pack_flags):
1612
1610
  """Header schema for PCAP-NG ``pack_flags`` options."""
1613
1611
 
1614
1612
  #: Flags.
@@ -1633,7 +1631,7 @@ class PACK_FlagsOption(_PACK_Option):
1633
1631
 
1634
1632
 
1635
1633
  @schema_final
1636
- class PACK_HashOption(_PACK_Option):
1634
+ class PACK_HashOption(_PACK_Option, code=Enum_OptionType.pack_hash):
1637
1635
  """Header schema for PCAP-NG ``pack_hash`` options."""
1638
1636
 
1639
1637
  #: Hash algorithm.
@@ -1648,7 +1646,7 @@ class PACK_HashOption(_PACK_Option):
1648
1646
 
1649
1647
 
1650
1648
  @schema_final
1651
- class PacketBlock(BlockType):
1649
+ class PacketBlock(BlockType, code=Enum_BlockType.Packet_Block):
1652
1650
  """Header schema for PCAP-NG Packet Block (obsolete)."""
1653
1651
 
1654
1652
  __payload__ = 'packet_data'
@@ -1676,16 +1674,7 @@ class PacketBlock(BlockType):
1676
1674
  length=lambda pkt: pkt['length'] - 32 - pkt['captured_length'] - len(pkt['padding_data']),
1677
1675
  base_schema=_PACK_Option,
1678
1676
  type_name='type',
1679
- registry=collections.defaultdict(lambda: UnknownOption, {
1680
- Enum_OptionType.opt_endofopt: EndOfOption,
1681
- Enum_OptionType.opt_comment: CommentOption,
1682
- Enum_OptionType.opt_custom_2988: CustomOption,
1683
- Enum_OptionType.opt_custom_2989: CustomOption,
1684
- Enum_OptionType.opt_custom_19372: CustomOption,
1685
- Enum_OptionType.opt_custom_19373: CustomOption,
1686
- Enum_OptionType.pack_flags: EPB_FlagsOption,
1687
- Enum_OptionType.pack_hash: EPB_HashOption,
1688
- }),
1677
+ registry=Option.registry['pack'],
1689
1678
  eool=Enum_OptionType.opt_endofopt,
1690
1679
  )
1691
1680
  #: Padding.