Skip to content

Commit 4ebfd5e

Browse files
committed
docs(contributing): record protocol member order convention
Group members as properties, methods, data models, utilities, per the owner ruling. Reference: IPv4, TCP, UDP, ARP and Ethernet.
1 parent 545ad0c commit 4ebfd5e

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

‎docs/source/contributing/conventions/index.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ House Conventions
1717
* :ref:`extension-header-subclassing` -- a protocol class hierarchy;
1818
* :ref:`protocol-family-grouping` -- how a protocol family's base and members
1919
spell :meth:`~pcapkit.protocols.protocol.Protocol.id`;
20+
* :ref:`protocol-member-order` -- the order of members in a protocol class body;
2021
* :ref:`protocol-layer-placement` -- which subpackage a dissector belongs in;
2122
* :ref:`process` -- the repository rather than any of its code;
2223
* :ref:`documentation` -- the prose itself, on these pages and in the API
@@ -41,6 +42,7 @@ House Conventions
4142
registry-protocol
4243
extension-header-subclassing
4344
protocol-family-grouping
45+
protocol-member-order
4446
protocol-layer-placement
4547
process
4648
documentation
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
.. _protocol-member-order:
2+
3+
Protocol Member Order
4+
---------------------
5+
6+
The order of members inside a protocol class body. Settled by the owner as a
7+
ruling, so a new dissector and a refactor land in the same layout.
8+
9+
Each group sits under its section comment, spelled as the repo spells it:
10+
``# Properties.``, ``# Methods.``, ``# Data models.`` and ``# Utilities.``
11+
12+
The Order
13+
~~~~~~~~~
14+
15+
#. **Properties.** Every ``@property`` member.
16+
#. **Methods.** Public methods: mostly ``id()``, ``read()``, ``make()`` and
17+
``register_xxx()``.
18+
#. **Data models.** Every dunder name: ``__index__``, ``__length_hint__``,
19+
``__init__``, ``__new__``, ``__post_init__`` and any other.
20+
#. **Utilities.** Everything else, mostly private methods. A ``_read_xxx()`` comes
21+
before its ``_make_xxx()``, and any such pair keeps that order.
22+
23+
Example
24+
~~~~~~~
25+
26+
.. code-block:: python
27+
28+
class Foo(Protocol[Data_Foo, Schema_Foo]):
29+
30+
# Methods.
31+
def read(self, length, *, ...):
32+
...
33+
34+
def make(self, ...):
35+
...
36+
37+
# Utilities.
38+
def _read_foo_field(self, ...):
39+
...
40+
41+
def _make_foo_field(self, ...):
42+
...
43+
44+
The Reference
45+
~~~~~~~~~~~~~
46+
47+
:class:`~pcapkit.protocols.internet.ipv4.IPv4`,
48+
:class:`~pcapkit.protocols.transport.tcp.TCP`,
49+
:class:`~pcapkit.protocols.transport.udp.UDP`,
50+
:class:`~pcapkit.protocols.link.arp.ARP` and
51+
:class:`~pcapkit.protocols.link.ethernet.Ethernet` follow this order. When a
52+
new class is unclear, match them.

0 commit comments

Comments
 (0)