Protocol Family

pcapkit.protocols holds the protocol families.

Every protocol class subclasses ProtocolBase, parsing a packet from its octets or building one from field values:

        flowchart LR
    A{{ProtocolMeta}} -.->|metaclass| B(ProtocolBase)

    %% The layers are declared in this order so that ARP --> RARP and
    %% Raw --> FTP_DATA stay short instead of crossing the other layers.

    subgraph misc [Miscellaneous]
        subgraph pcap [PCAP Format]
            Header & Frame
        end

        subgraph pcapng [PCAP-NG Format]
            PCAPNG
        end

        subgraph checksum [Checksum Pseudo-Headers]
            IP_Pseudo
        end

        Raw & NoPayload
    end

    subgraph application [Application Layer]
        Application --> HTTP & FTP & FTP_DATA & NGAP & OSPF & RARP & SSL

        subgraph http [HTTP Family]
            HTTP --> h1["HTTP/1.*"] & h2["HTTP/2"]
        end

        subgraph ftp [FTP Family]
            FTP & FTP_DATA
        end

        subgraph rarp [RARP Family]
            RARP --> DRARP
        end

        subgraph ssl [SSL Family]
            SSL --> TLS & DTLS & SSLv2
            TLS --> SSLv3
        end
    end

    subgraph link [Link Layer]
        Link --> Ethernet & L2TP & LinuxSLL & Loopback & VLAN & ARP

        subgraph arp [ARP Family]
            ARP --> InARP
        end

        subgraph vlan [VLAN Family]
            VLAN --> C_Tag & S_Tag
        end

        subgraph l2tp [L2TP Family]
            L2TP --> L2TPv2
        end

        subgraph sll [LinuxSLL Family]
            LinuxSLL --> LinuxSLL1 & LinuxSLL2
        end
    end

    subgraph internet [Internet Layer]
        Internet --> IPX & IP & ICMP & IPsec & IPv6_Ext & IGMP

        subgraph ip [IP Family]
            IP --> IPv4 & IPv6
        end

        subgraph icmp [ICMP Family]
            ICMP --> ICMPv4 & ICMPv6
        end

        subgraph ipsec [IPsec Family]
            IPsec --> AH & ESP
        end

        subgraph ipv6ext [IPv6 Extension Header]
            IPv6_Ext --> IPv6-Frag & IPv6-Opts & IPv6-Route & HOPOPT & MH & HIP
        end

        subgraph igmp [IGMP Family]
            IGMP --> IGMPv1 & IGMPv2 & IGMPv3
        end
    end

    subgraph transport [Transport Layer]
        Transport --> TCP & UDP & SCTP & DCCP
    end

    B --> Link & Internet & Transport & Application

    B --> Header & Frame & PCAPNG & Raw & NoPayload & IP_Pseudo
    Raw --> FTP_DATA
    ARP --> RARP
    IPv6_Ext --> AH & ESP

    B --> C(Protocol)
    C --> D([user customisation ...])

    click A "protocol.html#pcapkit.protocols.protocol.ProtocolMeta"
    click B "protocol.html#pcapkit.protocols.protocol.ProtocolBase"
    click C "protocol.html#pcapkit.protocols.protocol.Protocol"
    click D "../../ext.html#customising-protocols"

    click Link "link/link.html#pcapkit.protocols.link.link.Link"
    click Ethernet "link/ethernet.html#pcapkit.protocols.link.ethernet.protocol.Ethernet"
    click L2TP "link/l2tp.html#pcapkit.protocols.link.l2tp.protocol.L2TP"
    click L2TPv2 "link/l2tpv2.html#pcapkit.protocols.link.l2tpv2.protocol.L2TPv2"
    click LinuxSLL "link/linux_sll.html#pcapkit.protocols.link.linux_sll.protocol.LinuxSLL"
    click LinuxSLL1 "link/linux_sll1.html#pcapkit.protocols.link.linux_sll1.protocol.LinuxSLL1"
    click LinuxSLL2 "link/linux_sll2.html#pcapkit.protocols.link.linux_sll2.protocol.LinuxSLL2"
    click Loopback "link/loopback.html#pcapkit.protocols.link.loopback.protocol.Loopback"
    click VLAN "link/vlan.html#pcapkit.protocols.link.vlan.protocol.VLAN"
    click C_Tag "link/c_tag.html#pcapkit.protocols.link.c_tag.protocol.C_Tag"
    click S_Tag "link/s_tag.html#pcapkit.protocols.link.s_tag.protocol.S_Tag"
    click ARP "link/arp.html#pcapkit.protocols.link.arp.protocol.ARP"
    click InARP "link/inarp.html#pcapkit.protocols.link.inarp.protocol.InARP"

    click Internet "internet/internet.html#pcapkit.protocols.internet.internet.Internet"
    click AH "internet/ah.html#pcapkit.protocols.internet.ah.protocol.AH"
    click ESP "internet/esp.html#pcapkit.protocols.internet.esp.protocol.ESP"
    click HIP "internet/hip.html#pcapkit.protocols.internet.hip.protocol.HIP"
    click IGMP "internet/igmp.html#pcapkit.protocols.internet.igmp.protocol.IGMP"
    click IGMPv1 "internet/igmpv1.html#pcapkit.protocols.internet.igmpv1.protocol.IGMPv1"
    click IGMPv2 "internet/igmpv2.html#pcapkit.protocols.internet.igmpv2.protocol.IGMPv2"
    click IGMPv3 "internet/igmpv3.html#pcapkit.protocols.internet.igmpv3.protocol.IGMPv3"
    click HOPOPT "internet/hopopt.html#pcapkit.protocols.internet.hopopt.protocol.HOPOPT"
    click ICMP "internet/icmp.html#pcapkit.protocols.internet.icmp.protocol.ICMP"
    click ICMPv4 "internet/icmpv4.html#pcapkit.protocols.internet.icmpv4.protocol.ICMPv4"
    click ICMPv6 "internet/icmpv6.html#pcapkit.protocols.internet.icmpv6.protocol.ICMPv6"
    click IP "internet/ip.html#pcapkit.protocols.internet.ip.protocol.IP"
    click IPsec "internet/ipsec.html#pcapkit.protocols.internet.ipsec.protocol.IPsec"
    click IPv4 "internet/ipv4.html#pcapkit.protocols.internet.ipv4.protocol.IPv4"
    click IPv6 "internet/ipv6.html#pcapkit.protocols.internet.ipv6.protocol.IPv6"
    click IPv6_Ext "internet/ipv6_ext.html#pcapkit.protocols.internet.ipv6_ext.protocol.IPv6_Ext"
    click IPv6-Frag "internet/ipv6_frag.html#pcapkit.protocols.internet.ipv6_frag.protocol.IPv6_Frag"
    click IPv6-Opts "internet/ipv6_opts.html#pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts"
    click IPv6-Route "internet/ipv6_route.html#pcapkit.protocols.internet.ipv6_route.protocol.IPv6_Route"
    click IP_Pseudo "misc/checksum.html#pcapkit.protocols.misc.checksum.ip_pseudo.protocol.IP_Pseudo"
    click IPX "internet/ipx.html#pcapkit.protocols.internet.ipx.protocol.IPX"
    click MH "internet/mh.html#pcapkit.protocols.internet.mh.protocol.MH"

    click Transport "transport/transport.html#pcapkit.protocols.transport.transport.Transport"
    click TCP "transport/tcp.html#pcapkit.protocols.transport.tcp.protocol.TCP"
    click UDP "transport/udp.html#pcapkit.protocols.transport.udp.protocol.UDP"
    click SCTP "transport/sctp.html#pcapkit.protocols.transport.sctp.protocol.SCTP"
    click DCCP "transport/dccp.html#pcapkit.protocols.transport.dccp.protocol.DCCP"

    click Application "application/application.html#pcapkit.protocols.application.application.Application"
    click HTTP "application/http.html#pcapkit.protocols.application.http.protocol.HTTP"
    click h1 "application/httpv1.html#pcapkit.protocols.application.httpv1.protocol.HTTPv1"
    click h2 "application/httpv2.html#pcapkit.protocols.application.httpv2.protocol.HTTPv2"
    click FTP "application/ftp.html#pcapkit.protocols.application.ftp.protocol.FTP"
    click FTP_DATA "application/ftp_data.html#pcapkit.protocols.application.ftp_data.protocol.FTP_DATA"
    click NGAP "application/ngap.html#pcapkit.protocols.application.ngap.protocol.NGAP"
    click OSPF "application/ospf.html#pcapkit.protocols.application.ospf.protocol.OSPF"
    click RARP "application/rarp.html#pcapkit.protocols.application.rarp.protocol.RARP"
    click DRARP "application/drarp.html#pcapkit.protocols.application.drarp.protocol.DRARP"
    click SSL "application/ssl.html#pcapkit.protocols.application.ssl.protocol.SSL"
    click SSLv2 "application/sslv2.html#pcapkit.protocols.application.sslv2.protocol.SSLv2"
    click TLS "application/tls.html#pcapkit.protocols.application.tls.protocol.TLS"
    click SSLv3 "application/sslv3.html#pcapkit.protocols.application.sslv3.protocol.SSLv3"
    click DTLS "application/dtls.html#pcapkit.protocols.application.dtls.protocol.DTLS"

    click Raw "misc/raw.html#pcapkit.protocols.misc.raw.protocol.Raw"
    click NoPayload "misc/no_payload.html#pcapkit.protocols.misc.no_payload.protocol.NoPayload"
    click PCAPNG "misc/pcapng.html#pcapkit.protocols.misc.pcapng.protocol.PCAPNG"
    click Header "misc/pcap.html#pcapkit.protocols.misc.pcap.header.protocol.Header"
    click Frame "misc/pcap.html#pcapkit.protocols.misc.pcap.frame.protocol.Frame"
    

Protocol Registry

ProtocolBase.__registry__ maps names to protocol classes. ProtocolMeta.registry reads it as AnyProtocol.registry, a read-only view importing nothing, and ProtocolBase.get_protocol returns the class a name maps to.

Removed in version 1.6.0: pcapkit.protocols.__proto__, with no alias: read ProtocolBase.__registry__ through ProtocolBase.get_protocol instead (#2763).

Header Schema

Removed in version 1.6.0: pcapkit.protocols.schema.schema, with no alias: the module moved here. The pcapkit.protocols.schema.application, pcapkit.protocols.schema.internet, pcapkit.protocols.schema.link, pcapkit.protocols.schema.misc, pcapkit.protocols.schema.misc.checksum, pcapkit.protocols.schema.misc.pcap and pcapkit.protocols.schema.transport subpackages, and the header schemas they and pcapkit.protocols.schema collected, with no alias: each protocol’s are in the schema module of its own package, such as pcapkit.protocols.link.vlan.schema (#2534).

Removed in version 1.6.0: pcapkit.protocols.schema.schema.keep_short_read and pcapkit.protocols.schema.schema.replay_short_read, now pcapkit.corekit.schema.shortread.keep_short_read() and pcapkit.corekit.schema.shortread.replay_short_read() (#2674).

class pcapkit.protocols.schema.Schema[_VT](dict_=None, **kwargs)[source]

Bases: ReduceAsProtocol2, Mapping[str, _VT], Generic[_VT]

Schema for protocol headers.

Note

Building a schema directly does not range-check its field values. A NumberField masks an out-of-range integer to its width on packing, so e.g. 70000 in a two-octet field packs as 0x1170. The range checks live in each protocol’s make(), and in a field whose values have a range of their own, such as PortEnumField (#2314).

__fields__: OrderedDict[str, FieldBase]

Mapping of fields.

__payload__: str = 'payload'

Field name of the payload.

__additional__: list[str]

List of additional built-in names.

__excluded__: list[str]

List of names to be excluded from dict conversion.

classmethod from_dict(dict_=None, **kwargs)[source]

Create a new instance.

  • If dict_ is a mapping, then does: for k in dict_: self[k] = dict_[k].

  • If dict_ is present and not a mapping, then does: for k, v in dict_: self[k] = v.

  • In either case, and if dict_ is not present, this is followed by: for k, v in kwargs.items(): self[k] = v.

Parameters:
Return type:

Self

to_dict()[source]

Convert Schema into dict.

Important

Only a nested Schema that is an attribute’s direct value is converted into dict; one held within another type, such as list, tuple or set, is left intact.

Note

A schema unpacked as the value of a SchemaField that left part of the field’s span unread carries those octets under a __remainder__ key, and the number of octets it did read under __remainder_offset__. from_dict() accepts both back, so that the rebuilt field still packs them (#1380). The keys are absent otherwise.

A schema whose data ended inside one of its fields carries the __short_read__ that unpack() recorded, and from_dict() accepts it back, likewise.

Return type:

dict[str, _VT]

to_bytes()[source]

Convert Schema into bytes.

Return type:

bytes

get_payload(name=None)[source]

Get payload of Schema.

Parameters:

name (str | None) – Name of the payload field.

Return type:

bytes

Returns:

Payload of Schema as bytes.

pack(packet=None)[source]

Pack Schema into bytes.

Parameters:

packet (dict[str, Any] | None) – Packet data.

Return type:

bytes

Returns:

Packed Schema as bytes.

Notes

The packet’s length being unknown, __length__ defaults to -1, which Field takes as a placeholder; give __length__ to pack the correct length.

pre_pack(packet)[source]

Prepare packet data for packing process.

Parameters:

packet (dict[str, Any]) – packet data

Note

This method is expected to directly modify any data stored in the packet and thus no return is required.

classmethod unpack(data, length=None, packet=None)[source]

Unpack bytes into Schema.

Parameters:
Return type:

Self

Returns:

Unpacked data as Schema.

Notes

packet carries the bookkeeping keys below. For a nested schema, unpacked through a SchemaField, it is the context nested_packet_context() builds: a name this schema does not declare falls through to the enclosing schema, which __packet__ also holds.

  • __length__ – the length of the remaining data, which sizes the payload field.

  • __option_padding__ – how much of an OptionField’s declared area it left after its end-of-option-list marker. data is rewound by as much of that unparsed remainder as was read, so the fields sized from this key read the remainder itself and record a cut inside it (#2685). What follows decides what it is: usually padding, but the PCAP-NG name resolution block reads further options from it.

  • __short_read__ – for the fields after the one the data ends inside, the (name, octets read) pair recorded, or that of a ForwardMatchField the data ends inside first, which the record leaves out as it consumes nothing. A field callback can so tell a value the end of the data left as zero from one read, and leave it to the short read.

  • __data_end__ – that length ends where the data does, as a ListField says of an item it counts. Fields running past length are then the cut the short read records, and do not warn that __length__ fell below zero (#2749).

  • __data_present__ – that data holds the data that many octets in, and past them the zeros a ListField of schema items filled it out with. The field a read crosses them in is given how many of its octets the data holds, under the same key, so a list there ends with the data (#2760).

The last three are cleared as unpacking starts, so a nested schema finds only its own.

A payload field of a declared length the data ends inside records a cut like any other field, so its layer’s rebuild reads as cut (#2711); one declaring no length takes what the message leaves, as a trailer does, and records nothing. A ListField whose octets hold fewer items than it counts records the cut too, the missing items being its shortfall.

Changed in version 1.6.0: The field the data ends inside is given to the fields after it, as __short_read__ in packet (#2727), a schema whose length ends with the data reads its fields past it as cut, not as a negative length (#2749), and the field a read crosses the end of the data in, inside zeros filled out past it, is told where it ends (#2760).

classmethod pre_unpack(packet)[source]

Prepare packet data for unpacking process.

Parameters:

packet (dict[str, Any]) – packet data

Note

This method is expected to directly modify any data stored in the packet and thus no return is required.

post_process(packet)[source]

Revise schema data after packing and/or unpacking process.

Parameters:

packet (dict[str, Any]) – Unpacked data.

Return type:

Schema

Returns:

Revised schema.

classmethod __init_subclass__(*args, **kwargs)[source]

Refuse to derive from a finalised schema.

final() only informs the type checker: it records __final__ and leaves the class subclassable. A schema schema_final() finalises carries an __init__ generated from its __fields__ at that moment, which cannot set a field a subclass adds, so the subclass is refused.

Parameters:
  • *args (Any) – Arbitrary positional arguments.

  • **kwargs (Any) – Arbitrary keyword arguments in class definition.

Raises:

SchemaError – If any class in cls’s ancestry carries the __final__ marker in its own __dict__.

static __new__(cls, *args, **kwargs)[source]

Create a new instance.

The class will try to automatically generate __init__ method with one keyword parameter per field in __fields__, which is inspired by PEP 557 (dataclasses).

Note

Whether cls still needs finalising is read from its own __dict__, never inherited (#1498). Each class is finalised on its first construction, whatever its ancestors’ state, so a subclass of a BASE ancestor still gets its own __builtin__, __excluded__ and generated __init__, and a @final class under a BASE ancestor is refused like any other.

Parameters:
  • *args (_VT) – Arbitrary positional arguments.

  • **kwargs (_VT) – Arbitrary keyword arguments.

Raises:

SchemaError – If cls was marked with final() but never finalised by schema_final(), i.e. it carries __final__ in its own __dict__ without FINAL.

Return type:

Self

_cut_short_read()[source]

Cut the packed buffers back to the octets a short read consumed.

A schema whose data ended inside one of its fields records, as __short_read__, that field’s name and how many of its octets were there (see unpack()). Its value is read as though the missing octets were zeros, so packing it writes the field at full width and every field after it besides, none of which was captured. Only the octets read are kept here, so a truncated header packs back to exactly what was captured (#1458).

class pcapkit.protocols.schema.EnumSchema[_ET: Enum](*args, **kwargs)[source]

Bases: Schema, Generic[_ET]

Schema with enumeration mapping support.

Examples

Subclass it with the enumeration:

class MySchema(EnumSchema[MyEnum]):

    # optional, set the default schema for enumeration mapping
    # if the enumeration number is not found in the mapping
    __default__ = lambda: UnknownSchema  # by default, None

then subclass that per code, or list of codes:

class OneSchema(MySchema, code=MyEnum.ONE):
    ...

class MultipleSchema(MySchema, code=[MyEnum.TWO, MyEnum.THREE]):
    ...

or optionally, using the register() method to register a schema to the enumeration mapping:

MySchema.register(MyEnum.ZERO, ZeroSchema)

And now you can access the enumeration mapping via the registry property (more specifically, class attribute):

>>> MySchema.registry[MyEnum.ONE]  # OneSchema
__default__: Callable[[], Type[Self]]

Callback to return the default schema for enumeration mapping, by default is a lambda: None statement.

__enum__: DefaultDict[_ET, Type[Self]]

Mapping of enumeration numbers to schemas.

property registry: DefaultDict[_ET, Type[Self]]

Mapping of enumeration numbers to schemas.

Note

This property answers on an instance; on the class, the same mapping is served by EnumMeta.registry.

Important

See EnumMeta.registry: the returned mapping is a _EnumRegistry, so looking up an unregistered code returns the default schema without recording code as if it had been registered.

classmethod register(code, schema)[source]

Register enumeration to __enum__ mapping.

Parameters:
  • code (_ET) – Enumeration code.

  • schema (Type[Self]) – Enumeration schema.

Warns:

pcapkit.utilities.warnings.RegistryWarning – If code is already registered, naming the displaced schema and its replacement.

Note

Each registrar in pcapkit.foundation.registry.protocols that takes a schema registers both halves of one binding, a parser through e.g. IPv4.register_option and a schema through this method, and both warn on an overwrite.

Registering the same schema object again is a silent no-op. Presence is a faithful test only because _EnumRegistry does not record a miss.

pcapkit.protocols.misc.pcapng.schema.Option overrides this method with a namespaced registry of its own, guarded separately.

classmethod __init_subclass__(code=None, *args, **kwargs)[source]

Register enumeration to registry mapping.

Parameters:
  • code (_ET | Iterable[_ET] | None) – Enumeration code. It can be either a single enumeration or a list of enumerations.

  • *args (Any) – Arbitrary positional arguments.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type:

None

A subclass given code is registered under it in registry; one without is not.

Warns:

pcapkit.utilities.warnings.RegistryWarning – If any of code is already registered, naming the displaced schema and its replacement, as register() does: a class declaration such as class MyOption(Option, code=...) writes the registry without calling it.

Notes

An undefined __enum__ becomes an _EnumRegistry defaulting to __default__.

To customise the mapping, override this method and define __enum__ manually. A plain collections.defaultdict defined so, as for the namespaced mapping of pcapkit.protocols.misc.pcapng.schema.Option, is swapped for an _EnumRegistry before anything else can hold it.

@pcapkit.protocols.schema.schema_final(cls, *, _finalised=True)[source]

Finalise schema class.

This decorator generates the attributes and methods of the decorated Schema class once, rather than at runtime.

Notes

Use it on the final class only. With _finalised=True it seals the class against subclassing, which Schema.__init_subclass__() enforces, and marks it with final(), so @schema_final implies @final; writing both is harmless. Schema.__new__() refuses @final without this decorator, where @final is final(), or typing.final() on Python 3.11 and up. Below 3.11, typing.final() sets no __final__ (gh-90500), so a class marked with it is not refused.

Applying it to the same class a second time only warns, and the class comes back finalised and usable.

Parameters:
  • cls (_ST) – Schema class.

  • _finalised (bool) – Whether to make the schema class finalised.

Return type:

_ST

Returns:

Finalised schema class.

Warns:

pcapkit.utilities.warnings.SchemaWarning – If cls has already been finalised by this function, i.e. it carries FINAL in its own __dict__. The class is returned untouched.

Changed in version 1.5.0: A class finalised with _finalised=True refuses to be subclassed, and a schema marked @final without this decorator cannot be instantiated (#778).

Internal Definitions

class pcapkit.protocols.schema.SchemaMeta(name, bases, attrs, /, **kwargs)[source]

Bases: ABCMeta

Meta class to add dynamic support to Schema.

It generates the attributes of the Schema class:

  • Schema.__fields__ maps each field name, the attribute name, to its Field object, which defines and parses the header. It is populated from the class attributes.

    See also

    The __prepare__() method sets up the initial field dictionary from those of the base classes; during class creation, Field.__set_name__ names each field object and adds it to the dictionary.

  • Schema.__additional__ and Schema.__excluded__ list names to include in or exclude from the field dictionary, populated from the class attributes of the class and its bases.

    Note

    This metaclass’s __new__ inherits both lists from the base classes and extends them with the subclass’s own.

    class A(Schema):
        __additional__ = ['a', 'b']
    
    class B(A):
        __additional__ = ['c', 'd']
    
    class C(B):
        __additional__ = ['e', 'f']
    
    print(A.__additional__)  # ['a', 'b']
    print(B.__additional__)  # ['a', 'b', 'c', 'd']
    print(C.__additional__)  # ['a', 'b', 'c', 'd', 'e', 'f']
    
classmethod __prepare__(name, bases, /, **kwds)[source]

Prepare the namespace for the schema class.

Parameters:
  • name (str) – Name of the schema class.

  • bases (tuple[type, ...]) – Base classes of the schema class.

  • **kwds (Any) – Additional keyword arguments at class definition.

Return type:

Mapping[str, object]

This method is used to create the initial field dictionary __fields__ for the schema class.

class pcapkit.protocols.schema.EnumMeta[_ET: Enum](name, bases, attrs, /, **kwargs)[source]

Bases: SchemaMeta, Generic[_ET]

Meta class to add dynamic support for EnumSchema.

It adds registry to subclasses: a read-only class property returning the EnumSchema.__enum__ mapping.

property registry: DefaultDict[_ET, Type[EnumSchema]]

Mapping of enumeration numbers to schemas.

Important

The returned mapping is a _EnumRegistry, not a plain collections.defaultdict: indexing it with an unregistered code still returns EnumSchema.__default__’s schema, but does not insert that code. See _EnumRegistry for why that distinction matters.

class pcapkit.protocols.schema._EnumRegistry[source]

Bases: defaultdict

A registry collections.defaultdict that never inserts a miss.

EnumSchema.registry (and its class-level twin, EnumMeta.registry) is read with a bare registry[code] across the schema layer, e.g. Option.registry[type]. A plain collections.defaultdict would insert what default_factory returns on the first miss, and the registry lives on the class, so one packet with an unrecognised code would grow it for the rest of the process, and make a later, legitimate EnumSchema.register() report an overwrite that never happened.

The fallback is how an unknown option, chunk or block gets its Unknown*/Unassigned* schema, so this subclass still returns it, without recording it, as Protocol._lookup_registry does for the __proto__ family.

__missing__(key)[source]

Return the fallback for an unregistered key, without storing it.

Parameters:

key (Any) – Registry key that is not registered.

Return type:

Any

Returns:

What default_factory returns. The registry is left as it was, so key stays unregistered.

Raises:

KeyError – If default_factory is None.

Type Variables

pcapkit.protocols.schema._VT: Any
pcapkit.protocols.schema._ET: enum.Enum
pcapkit.protocols.schema._ST: Type[pcapkit.protocols.schema.Schema]

Data Model

Removed in version 1.6.0: pcapkit.protocols.data.data and pcapkit.protocols.data.protocol, with no alias: the modules merged here. The pcapkit.protocols.data.application, pcapkit.protocols.data.internet, pcapkit.protocols.data.link, pcapkit.protocols.data.misc, pcapkit.protocols.data.misc.checksum, pcapkit.protocols.data.misc.pcap and pcapkit.protocols.data.transport subpackages, and the data models they and pcapkit.protocols.data collected, with no alias: each protocol’s are in the data module of its own package, such as pcapkit.protocols.link.vlan.data (#2534).

class pcapkit.protocols.data.Data(*args, **kwargs)[source]

Bases: Info

Base class for data models.

The __next_name__, __next_type__, __short_read__ and __short_width__ keys are metadata, listed in __included__ and __excluded__. Protocol.from_data dispatches the payload on the first two alone, cuts a short read back on the third, and reads it at the width the fourth records.

to_dict() carries them, so from_data(info.to_dict()) rebuilds as from_data(info) does; the dumpers and repr leave them out. A hand-written dict needs them too, and for IPv6 the extension header chain under __exthdr__: without the first two no payload layer is dispatched, and without __exthdr__ no IPv6 extension header is rebuilt (#2003).

__included__: list[str]

Metadata keys that to_dict() carries, for a rebuild to read.

__excluded__: list[str]

Metadata keys that repr, str and the dumps leave out.

See also

Protocol._decode_next_layer, which inserts __next_name__ and __next_type__.