Skip to content

Treat None dispatch fields as defaults in encode_dict for types 6/8/24 - #231

Merged
M0r13n merged 1 commit into
M0r13n:mainfrom
rifatkinali:fix/encode-none-dispatch
Oct 11, 2026
Merged

M0r13n merged 1 commit into
M0r13n:mainfrom
rifatkinali:fix/encode-none-dispatch

Conversation

@rifatkinali

Copy link
Copy Markdown
Contributor

Fixes #228.

Problem

A dict produced by asdict() of a truncated type 6, 8 or 24 message carries None for the fields that were not present in the payload. The create() dispatchers of these types call int() directly on dac/fid (6, 8), wmo (8 DAC 1 FID 21) and mmsi/partno (24), so

>>> encode_dict(decode(b"!AIVDM,1,1,,A,6B?1,0*5C").asdict())
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

The generic Payload.create() already treats None as "use the default" for every other field; only the dispatch step was inconsistent.

Change

  • _dispatch_int(kwargs, key, default=0): reads an integer dispatch field and treats None like a missing key.
  • Used in MessageType6.create, MessageType8.create, MessageType8Dac1Fid21.create (wmo) and MessageType24.create (mmsi, partno). No behaviour change for present values; partno=None selects Part A like a missing partno would.
  • Tests: truncated round trip for all three types (decode → asdict → encode_dict → decode, type and MMSI preserved) and explicit None dispatch fields. Both tests fail on main before the fix.

Verification

🤖 Generated with Claude Code

A dict produced by asdict() of a truncated type 6, 8 or 24 message carries
None for the fields that were not present in the payload. The create()
dispatchers of these types called int() directly on dac/fid (6, 8), wmo
(8 DAC1 FID21) and mmsi/partno (24), so encode_dict(decode(x).asdict())
raised a plain TypeError instead of encoding the message.

Route those reads through a small helper that treats None like a missing
key, which is what the generic Payload.create() already does for every
other field. Regression tests cover the truncated round trip for all three
types and explicit None values.

Fixes M0r13n#228

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>

@M0r13n M0r13n left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@M0r13n
M0r13n merged commit b4d5e3e into M0r13n:main Oct 11, 2026
6 checks passed
Sign up for free to 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.

encode_dict(decode(raw).asdict()) raises TypeError for truncated type 6/8/24 messages

2 participants