Skip to content

Make Packet pull its weight: type indexing, hashing, delete .payload - #130

Merged
EONRaider merged 2 commits into
masterfrom
claude/decoder-depth-polish-8m54to
Sep 4, 2026
Merged

Make Packet pull its weight: type indexing, hashing, delete .payload#130
EONRaider merged 2 commits into
masterfrom
claude/decoder-depth-polish-8m54to

Conversation

@EONRaider

Copy link
Copy Markdown
Owner

Summary

Closes#90. Packet gains type-keyed access and becomes hashable; the redundant .payload property is deleted, which is the breaking change behind the 2.0.0 major bump (Tier 2, #104).

What's included

  • Packet.__getitem__ branches on int (unchanged positional indexing) vs. a protocol type (packet[TCP] returns the first matching layer in wire order, KeyError on no match).
  • Packet.get(TCP) — same lookup, returns None on no match instead of raising (dict-like .get() convention).
  • Packet.__hash__, mirroring exactly what the existing __eq__ compares (layers, and stopped_by's type and str(), not identity — ProtocolError has no custom __eq__). Packet is now usable as a dict key or set member.
  • Breaking:Packet.payload is deleted outright (not deprecated). It was always exactly bytes(self), a redundant duplicate of __bytes__/bytes(packet), which is the unambiguous spelling and already existed.
  • tests/test_packet.py: type-key hit/miss, int-key hit/miss (unchanged), .get() hit/miss, hash consistency with == (equal packets hash equal, stopped_by changes the hash), Packet as a dict key / set member, .payload raises AttributeError.
  • CHANGELOG.md entry under ## [Unreleased] (### Removed for the breaking change, ### Added for the new capabilities).

Verification

  • uv run --frozen ruff check . and uv run --frozen ruff format --check . are clean
  • uv run --frozen mypy is clean (strict)
  • uv run --frozen pytest passes locally
  • uv run --frozen python scripts/benchmark.py --check --threshold 15 — within threshold (+35.2% vs. baseline)
  • CHANGELOG.md has an entry under ## [Unreleased]

No new protocol/dispatch change, so that checklist block doesn't apply.

Notes

Per the roadmap's working agreement (#107), this is the first of three remaining Tier 2 issues (#90#89#92) — merged one at a time, not auto-merged.


🤖 Generated with Claude Code

https://claude.ai/code/session_01SVCFe7B1U5VeJRoUbx24vb


Generated by Claude Code

Packet[TCP] returns the first matching layer in wire order (KeyError
on no match); Packet.get(TCP) returns None instead. packet[0] keeps
indexing positionally — __getitem__ branches on int vs type.
Packet.__hash__ mirrors exactly what __eq__ already compares (layers,
and stopped_by's type + str(), not identity, since ProtocolError has
no custom __eq__), so Packet is now usable as a dict key or set
member.
BREAKING: Packet.payload is deleted outright. It was always exactly
bytes(self), a redundant duplicate of __bytes__/bytes(packet), which
is the unambiguous spelling. This is the breaking change behind the
2.0.0 major bump.
Closes#90.
Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SVCFe7B1U5VeJRoUbx24vb
Adds the packet[TCP] / packet.get(TCP) example alongside the existing
packet[1] positional one in the decode_frame() walkthrough (#90).
Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SVCFe7B1U5VeJRoUbx24vb
@EONRaider
EONRaider merged commit d81b4a1 into masterSep 4, 2026
7 checks passed
This was referenced Sep 4, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make Packet pull its weight — type indexing, hashing, and a rename

2 participants

@EONRaider@claude