mirror of
https://github.com/agessaman/meshcore-bot.git
synced 2026-10-31 18:12:45 +00:00
decode_meshcore_packet, the path processor, the path chunkers, format_path_string and the route/payload type-name tables are now plain functions in packet_decode.py. MessageHandler keeps every old method as a delegate that supplies the configured prefix width and its logger, so callers and tests that patch decode_meshcore_packet on a handler still work. The existing quirk is preserved: path_info uses the configured width while path/path_hex follow the packet's own bytes-per-hop. Parity: decoding a sample of 4,009 real packets from the dev database (plus malformed inputs) at prefix widths 2 and 4, with the path and format helpers, produces byte-identical output before and after. A handler built with no bot attribute now decodes path_info at width 2 instead of falling into the error branch; only bare test objects can hit that.
20 lines
588 B
Python
20 lines
588 B
Python
"""split_path_hex: the shared multi-byte path chunker with its legacy fallback."""
|
|
|
|
import pytest
|
|
|
|
from modules.packet_decode import split_path_hex
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("path_hex", "hex_chars", "expected"),
|
|
[
|
|
("A1B2C3", 2, ["a1", "b2", "c3"]),
|
|
("A1B2C3D4", 4, ["a1b2", "c3d4"]),
|
|
("A1B2C3", 4, ["a1", "b2", "c3"]), # does not divide: one-byte fallback
|
|
("A1B2C3D4E5F6", 6, ["a1b2c3", "d4e5f6"]),
|
|
("", 4, []),
|
|
],
|
|
)
|
|
def test_split_path_hex(path_hex, hex_chars, expected):
|
|
assert split_path_hex(path_hex, hex_chars) == expected
|