Skip to content

refactor(corekit): add pad_length and PaddingField(align=, after=) - #2624

Merged
JarryShaw merged 1 commit into
mainfrom
refactor/2614-pad-length
Nov 2, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
refactor/2614-pad-length

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • refactor — changes neither behaviour nor performance

Description of your pull request and other information

Adds pcapkit.corekit.fields.strings.pad_length(length, align) (-length % align) beside PaddingField, as the owner chose on #2614 (1a), and a PaddingField(align=…, after=…) form that states what the padding aligns. The PCAP-NG, SCTP and HIP schemas adopt it in place of the alignment arithmetic they spelled five different ways. Existing PaddingField(length=…) callers are unchanged. The protocol-class padding arithmetic is left for a later #2614 group.

Behaviour is unchanged. Every converted expression matches the old one over exhaustive length ranges. All 23 sample captures regenerate identically, and every one of their 6,900 layers parses and rebuilds byte-for-byte. A Sonnet cross-review returned GOOD TO GO. The two padding mutants it found surviving now have tests that kill them.

Part of #2614

- strings.pad_length(length, align) returns -length % align; an align that
  is not a positive int raises IntError or FieldValueError.
- PaddingField takes align and after (a field name or a callable giving the
  padded length) as an alternative to length; length callers are unchanged.
- PCAP-NG schema: option, record and packet-data padding use align=; the
  option-area lengths, _spb_data_length and the journal check call pad_length.
- SCTP schema: padding_length, nested_length and whole_chunks_length call
  pad_length; padding_length keeps its clamps, so it stays a callback.
- HIP schema: parameter_total_len pads 4 + Length with pad_length.
- Left for a later #2614 group: the protocol-class padding arithmetic in
  misc/pcapng.py, internet/hip.py and transport/sctp.py, and in
  foundation/engines/pcapng.py.
- Tests: test_fields_pad_length_2614_unit; samples rebuild byte-identically.
@JarryShaw JarryShaw added this to the PyPCAPKit v1.6 milestone Nov 2, 2026
@JarryShaw JarryShaw added refactor Restructuring for its own sake — neither a fix nor a new capability (refactor: prefix) review: good-to-go Cross-review at the current head says ready; CI state is separate labels Nov 2, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

GOOD TO GO at f646eaf0e, from a Sonnet cross-review:

  • Every converted padding expression matched the old one over exhaustive ranges, about 20M evaluations.
  • All 23 captures, 6,900 layers, plus a 72,000-block PCAP-NG fuzz are identical to main.
  • The two mutants it found surviving now have killing tests.
  • One API note for you: after= names the length the padding follows. The reviewer found the name workable, though of= would read less like an ordering constraint. It is cheap to rename now.

@JarryShaw JarryShaw moved this to In review in PyPCAPKit Nov 2, 2026
@JarryShaw
JarryShaw merged commit ce9c370 into main Nov 2, 2026
61 of 62 checks passed
@JarryShaw
JarryShaw deleted the refactor/2614-pad-length branch November 2, 2026 04:31
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Nov 2, 2026
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Nov 2, 2026
JarryShaw added a commit that referenced this pull request Nov 2, 2026
… kinds into 1.6.0 (#2449)

- Added: pad_length and PaddingField's align/after form (#2624), and
  pcapkit.utilities.contextvars (#2623); the old private names get no
  entry, as for the other private API.
- Changed: the weekly Issue and PR Kinds workflow, beside the milestone
  workflow's entry (#2626).
- The conventions entry records where a context variable lives (#2623),
  and the role-kind citation rule with its test (#2626).
- No entry for #2626's heading and Mermaid fixes, #2564 or fa9af52.
- CHANGELOG.md regenerated; util/changelog_md.py --check passes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Restructuring for its own sake — neither a fix nor a new capability (refactor: prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant