From 3cd95db40583c61ff89d2bdf4a1091d4cc11a586 Mon Sep 17 00:00:00 2001 From: serversdown Date: Fri, 13 Nov 2026 13:39:44 -0500 Subject: [PATCH] feat(mlg): read Blastware .MLG files, every record's checksum verified minimateplus/mlg_file.py parses the measured format: an 18-byte prefix, then length-led 292-byte records, each with a CRC-16/AUG-CCITT over [0:288] stored little-endian. A record that fails its checksum is returned flagged, never silently dropped. One shared CRC function (minimateplus/crc.py) replaces micromate/setup_block's copy. Fixtures: 12 real .MLG files (DL2's ACH folder + 3 bench files) in tests/fixtures/mlg-11-9-26/, force-added. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01ALX2R9LdWawLzUxwewZGA1 --- micromate/setup_block.py | 12 +- minimateplus/crc.py | 23 ++++ minimateplus/mlg_file.py | 141 +++++++++++++++++++++ minimateplus/models.py | 46 +++++++ tests/fixtures/mlg-11-9-26/BE11529.MLG | Bin 0 -> 1186 bytes tests/fixtures/mlg-11-9-26/BE115292.MLG | Bin 0 -> 1186 bytes tests/fixtures/mlg-11-9-26/BE128443065.MLG | Bin 0 -> 894 bytes tests/fixtures/mlg-11-9-26/BE128443067.MLG | Bin 0 -> 1186 bytes tests/fixtures/mlg-11-9-26/BE128443068.MLG | Bin 0 -> 602 bytes tests/fixtures/mlg-11-9-26/BE128443155.MLG | Bin 0 -> 894 bytes tests/fixtures/mlg-11-9-26/BE128443156.MLG | Bin 0 -> 602 bytes tests/fixtures/mlg-11-9-26/BE6907750.MLG | Bin 0 -> 1478 bytes tests/fixtures/mlg-11-9-26/BE6907751.MLG | Bin 0 -> 18 bytes tests/fixtures/mlg-11-9-26/BE8081.MLG | Bin 0 -> 1186 bytes tests/fixtures/mlg-11-9-26/BE8081321.MLG | Bin 0 -> 2062 bytes tests/fixtures/mlg-11-9-26/BE94412.MLG | Bin 0 -> 1478 bytes tests/test_mlg_file.py | 110 ++++++++++++++++ 17 files changed, 322 insertions(+), 10 deletions(-) create mode 100644 minimateplus/crc.py create mode 100644 minimateplus/mlg_file.py create mode 100644 tests/fixtures/mlg-11-9-26/BE11529.MLG create mode 100644 tests/fixtures/mlg-11-9-26/BE115292.MLG create mode 100644 tests/fixtures/mlg-11-9-26/BE128443065.MLG create mode 100644 tests/fixtures/mlg-11-9-26/BE128443067.MLG create mode 100644 tests/fixtures/mlg-11-9-26/BE128443068.MLG create mode 100644 tests/fixtures/mlg-11-9-26/BE128443155.MLG create mode 100644 tests/fixtures/mlg-11-9-26/BE128443156.MLG create mode 100644 tests/fixtures/mlg-11-9-26/BE6907750.MLG create mode 100644 tests/fixtures/mlg-11-9-26/BE6907751.MLG create mode 100644 tests/fixtures/mlg-11-9-26/BE8081.MLG create mode 100644 tests/fixtures/mlg-11-9-26/BE8081321.MLG create mode 100644 tests/fixtures/mlg-11-9-26/BE94412.MLG create mode 100644 tests/test_mlg_file.py diff --git a/micromate/setup_block.py b/micromate/setup_block.py index daeaf43..d434064 100644 --- a/micromate/setup_block.py +++ b/micromate/setup_block.py @@ -15,6 +15,8 @@ from __future__ import annotations import struct +from minimateplus.crc import crc16_aug_ccitt as _crc16_aug_ccitt + from .models import MicromateSetup from .protocol import ProtocolError @@ -23,8 +25,6 @@ class SetupChecksumError(ProtocolError): """A config block's trailing CRC does not match its contents.""" -_CRC_POLY = 0x1021 -_CRC_INIT = 0x1D0F # CRC-16/AUG-CCITT _CONTENT_SIZE = 2092 # = content[0:2] (2090) + the 2-byte CRC # ── Head of the block ───────────────────────────────────────────────────────── @@ -60,14 +60,6 @@ _ACTIVE_MIC = 3 # block index (0-based) _MIC_TYPES = {2: "linear", 9: "sound_level"} -def _crc16_aug_ccitt(data: bytes) -> int: - c = _CRC_INIT - for b in data: - c ^= b << 8 - for _ in range(8): - c = ((c << 1) ^ _CRC_POLY) & 0xFFFF if c & 0x8000 else (c << 1) & 0xFFFF - return c - def crc_ok(content: bytes) -> bool: """True if a config block's trailing checksum matches its contents. diff --git a/minimateplus/crc.py b/minimateplus/crc.py new file mode 100644 index 0000000..1ba1db0 --- /dev/null +++ b/minimateplus/crc.py @@ -0,0 +1,23 @@ +""" +minimateplus/crc.py — Instantel's record checksum, shared by every reader that checks one. + +CRC-16/AUG-CCITT: poly 0x1021, init 0x1D0F, no reflection, no final XOR. The +same rule covers a Micromate's setup blocks (0x1A, 0x08, 0x2E; stored big-endian), +a Blastware event file's footer (big-endian) and every .MLG record (little-endian). +Each block says where its checksum sits; this module only computes it. +""" + +from __future__ import annotations + +_POLY = 0x1021 +_INIT = 0x1D0F + + +def crc16_aug_ccitt(data: bytes) -> int: + """CRC-16/AUG-CCITT of `data` (check value: b"123456789" -> 0xE5CC).""" + c = _INIT + for b in data: + c ^= b << 8 + for _ in range(8): + c = ((c << 1) ^ _POLY) & 0xFFFF if c & 0x8000 else (c << 1) & 0xFFFF + return c diff --git a/minimateplus/mlg_file.py b/minimateplus/mlg_file.py new file mode 100644 index 0000000..c3564fb --- /dev/null +++ b/minimateplus/mlg_file.py @@ -0,0 +1,141 @@ +""" +minimateplus/mlg_file.py — Blastware's monitor log (.MLG): reader and writer. + +Blastware writes one .MLG per call-in, named .MLG, holding what +the unit logged since the previous call-in: each time monitoring started, each +event, and each time it stopped and why. Measured on 1,273 DL2 files and 9 +bench files (2026-11-09; reference D.4, spec +docs/superpowers/specs/2026-11-09-mlg-unit-timeline-design.md): + + [18-byte prefix 10 00 01 80 00 00 "Instantel\\0" 07 2c] + [292-byte records ...] size is always 18 + 292*n + +Every record: + [0:2] length, uint16 LE = 290 + [2:4] id: 0e a0 the header record (first, carries the serial), 0e 80 a log record + [4:12] start: day, month, year LE, 0, hour, minute, second + [12:20] stop, same format; all zeros = no stop + [20:22] monitor-log flag word, uint16 LE (the event footer's, D.6.14); 0xFFFF = started + [22:24] trigger source, uint16 LE: 0x0001-0x0008 a channel, 0x0400 a histogram + [24:34] serial, NUL-padded ASCII + [34:288] text, NUL-padded; an event's starts 0x08 + its 8-byte time + [288:290] 00 00 + [290:292] CRC-16/AUG-CCITT over [0:288], little-endian + +An empty file is the prefix alone: no header record, no serial. Pure: no I/O +beyond reading the path it is given. +""" + +from __future__ import annotations + +import datetime +import struct +from pathlib import Path +from typing import Optional, Union + +from .crc import crc16_aug_ccitt +from .event_file_io import monitor_log_description +from .models import MlgFile, MlgRecord + +MLG_PREFIX = b"\x10\x00\x01\x80\x00\x00Instantel\x00\x07\x2c" +RECORD_SIZE = 292 +_RECORD_LENGTH = 290 +_HEADER_ID = b"\x0e\xa0" +_LOG_ID = b"\x0e\x80" +_EVENT_TIME_MARK = 0x08 +_TRIGGER_LEVEL_PREFIXES = ("Trigger Level :", "Trigger Level:") + + +class MlgFormatError(ValueError): + """The bytes are not a whole .MLG file.""" + + +def _ts(raw: bytes) -> Optional[datetime.datetime]: + """8-byte MLG time (year little-endian); all zeros = None. Raises ValueError.""" + if raw == bytes(8): + return None + year = struct.unpack_from(" bool: + return crc16_aug_ccitt(record[:288]) == struct.unpack_from(" Optional[str]: + line = text.split("\r", 1)[0] + for prefix in _TRIGGER_LEVEL_PREFIXES: + if line.startswith(prefix): + line = line[len(prefix):] + break + line = line.strip() + return line or None + + +def _log_record(index: int, rec: bytes) -> MlgRecord: + try: + start = _ts(rec[4:12]) + stop = _ts(rec[12:20]) + except ValueError as exc: + raise MlgFormatError(f"record {index}: a time cannot be decoded ({exc})") from None + if start is None: + raise MlgFormatError(f"record {index}: no start time") + flags, source = struct.unpack_from(" MlgFile: + """Parse the bytes of a .MLG file. + + Raises MlgFormatError when the bytes are not a whole .MLG. A record whose + checksum fails is returned with crc_ok=False (MlgFile.crc_failures lists + them); the caller decides what to do with it.""" + if len(data) < len(MLG_PREFIX) or not data.startswith(MLG_PREFIX): + raise MlgFormatError("not an MLG: the 18-byte Instantel prefix is missing") + body = data[len(MLG_PREFIX):] + if len(body) % RECORD_SIZE: + raise MlgFormatError(f"not an MLG: size {len(data)} is not 18 + 292*n") + records = [body[i:i + RECORD_SIZE] for i in range(0, len(body), RECORD_SIZE)] + if not records: + return MlgFile(serial=None) + for index, rec in enumerate(records): + length = struct.unpack_from(" 0], + header_crc_ok=_crc_ok(header), + ) + + +def read_mlg(path: Union[str, Path]) -> MlgFile: + """Read and parse a .MLG file.""" + return parse_mlg(Path(path).read_bytes()) diff --git a/minimateplus/models.py b/minimateplus/models.py index f017748..d34c59a 100644 --- a/minimateplus/models.py +++ b/minimateplus/models.py @@ -729,6 +729,52 @@ class MonitorLogEntry: return f"MonitorLog#{self.index} key={self.key} {start}→{stop}{dur}" +# ── Blastware monitor log (.MLG) ────────────────────────────────────────────── + +@dataclass +class MlgRecord: + """One log record of a Blastware .MLG file (minimateplus/mlg_file.py). + + Times are the unit's own local clock. `flags` is the monitor-log flag word + (the event footer's, reference D.6.14); 0xFFFF means monitoring started + and has no stop yet.""" + index: int # position in the file; 0 is the header record + start: datetime.datetime + stop: Optional[datetime.datetime] + flags: int + trigger_source: int # 0x0001-0x0008 a channel, 0x0400 a histogram, 0 none + serial: str + text_raw: bytes = field(repr=False) # record[34:288] exactly, for write_mlg + event_time: Optional[datetime.datetime] = None + text: str = "" # Blastware's text, after any event time + trigger_level: Optional[str] = None # e.g. "Geo: 0.0500 in/s Mic: 125.0 dB(L)", "Histogram" + description: str = "" # "Monitoring started", or Blastware's words + crc_ok: bool = True + + @property + def is_start(self) -> bool: + return self.flags == 0xFFFF + + +@dataclass +class MlgFile: + """A whole .MLG file: the serial from its header record and its log records, + in file order. An empty file (the 18-byte prefix alone) has neither.""" + serial: Optional[str] + records: list[MlgRecord] = field(default_factory=list) + header_crc_ok: bool = True + + @property + def empty(self) -> bool: + return self.serial is None and not self.records + + @property + def crc_failures(self) -> list[int]: + """Indexes of the records whose checksum fails (0 is the header record).""" + head = [] if self.header_crc_ok else [0] + return head + [r.index for r in self.records if not r.crc_ok] + + # ── MonitorStatus ───────────────────────────────────────────────────────────── @dataclass diff --git a/tests/fixtures/mlg-11-9-26/BE11529.MLG b/tests/fixtures/mlg-11-9-26/BE11529.MLG new file mode 100644 index 0000000000000000000000000000000000000000..7a0652e1689111fe9d81821651cb3c81ae958af3 GIT binary patch literal 1186 zcmWe&U~FJu@XRYNNz5xr&0%2IQDWpofxf&Xp8d+kI8EHau9e`ofAja~Fok5gM z1m^qy{}~t%VH8r7nVz0nq~McUmYQRw;E`EelAm6bmO^EgHRM6I=sU@SWx_zcONN?ETDm5$;iNjl#XCwWZ|BgZ>3ofxf&Xp8d+kI8EHau9e`ofAja~Fok5gM z1m^qy{}~t%VH8r7nVz0nq~McUmYSnrrQnfST#}z&l$Z-sKFsNq5Tq~?g@hHmE;9oI z3nGj-pg|}K4;FFXjzP QEh<44Ks9>U@UF800J^a;*Z=?k literal 0 HcmV?d00001 diff --git a/tests/fixtures/mlg-11-9-26/BE128443065.MLG b/tests/fixtures/mlg-11-9-26/BE128443065.MLG new file mode 100644 index 0000000000000000000000000000000000000000..82d31899aba2e954efdf4d33d092b26be4345c1b GIT binary patch literal 894 zcmWe&U~FJu@XRYNNz5xr&0%2IQDWpofxf&W-n3!OZ8EHbkbAVygz{>fGok2)n z3QUVIFbDvH0TD*-srgn426_gj1_lb5dHTf)zM08Z3Wi3edIkz9P8vR%!#vQgR)fNb X4HQOf47^}kNS8rjG>nkq{hK=g9Q7mT literal 0 HcmV?d00001 diff --git a/tests/fixtures/mlg-11-9-26/BE128443067.MLG b/tests/fixtures/mlg-11-9-26/BE128443067.MLG new file mode 100644 index 0000000000000000000000000000000000000000..f873d3107cb12ce28c6716d7a178bf3459a76ee5 GIT binary patch literal 1186 zcmWe&U~FJu@XRYNNz5xr&0%2IQDWpofxf&W-n3!OZ8EHbkbAVygz|Q%Kok2)n z8cd5YFbDvH0TD*-srgn426_gj1_lb5dHTf)zM08Z3Wi3edIkz9P8vR%!#vO$>_B0} z0SY5F240wF|Nlo0qmZJ^^z_ss1)tQi)EosXg^?C!7pKC*h*wPv99Fz)l8g+DNa=_J YDlA4YaCk$C67x{f94yp_GHvDr02};000000 literal 0 HcmV?d00001 diff --git a/tests/fixtures/mlg-11-9-26/BE128443068.MLG b/tests/fixtures/mlg-11-9-26/BE128443068.MLG new file mode 100644 index 0000000000000000000000000000000000000000..ce249da4238c3f84639ab55bdf53879938d09702 GIT binary patch literal 602 zcmWe&U~FJu@XRYNNz5xr&0%2IQDWpofxf&W-n3!OZ8EHbkbAVygz`^;7oq< C85Q^d literal 0 HcmV?d00001 diff --git a/tests/fixtures/mlg-11-9-26/BE128443155.MLG b/tests/fixtures/mlg-11-9-26/BE128443155.MLG new file mode 100644 index 0000000000000000000000000000000000000000..0834a3e8404f8bc3077b4f3b215e47d74314680e GIT binary patch literal 894 zcmWe&U~FJu@XRYNNz5xr&0%2IQDWpofxf&W-n3!OZ8EHbkbAVygAkX!Rok2)n z226`EFbDvH0TD*-srgn426_gj1_lb5dHTf)zM08Z3Wi3edIkz9P8vR%!#vRZzk$Mt YksBCBYz(|$T1b~cVKj`8;yv~<0ET`f0RR91 literal 0 HcmV?d00001 diff --git a/tests/fixtures/mlg-11-9-26/BE128443156.MLG b/tests/fixtures/mlg-11-9-26/BE128443156.MLG new file mode 100644 index 0000000000000000000000000000000000000000..bb3da16c764830f694c7b54d1bb51694c0e18bd8 GIT binary patch literal 602 zcmWe&U~FJu@XRYNNz5xr&0%2IQDWpofxf&W-n3!OZ8EHbkbAVygz{vfIok37v z5=;x}GAICp0TD*-srgn426_gj1_lb5dHTf)zM08Z3Wi3edIkz9P8vR%!#vP5-vI!f CVinu~ literal 0 HcmV?d00001 diff --git a/tests/fixtures/mlg-11-9-26/BE6907750.MLG b/tests/fixtures/mlg-11-9-26/BE6907750.MLG new file mode 100644 index 0000000000000000000000000000000000000000..a279df450ea0804e3eb52729a253f8a83c03abbe GIT binary patch literal 1478 zcmWe&U~FJu@XRYNNz5xr&0%2IQDWpofxtduTm}8L`aYDBDfnn4j%JGVwK}f|C zOp7ou2mr$Y5k~H*`Bn-BdIqKj1`3&Z`o#*qnaNfPhDN4(1_~)o8a|rCJk(aGgThD* z6h>?eykJ^LjzM8GjF948bRIm6gp~QfVKkbKkirMVJi!kNBXMXt0@I`E2rZ0q9{>P( CsXj{p literal 0 HcmV?d00001 diff --git a/tests/fixtures/mlg-11-9-26/BE6907751.MLG b/tests/fixtures/mlg-11-9-26/BE6907751.MLG new file mode 100644 index 0000000000000000000000000000000000000000..0ea2b8d4750889a2f30190edacd585009cfb8274 GIT binary patch literal 18 ZcmWe&U~FJu@XRYNNz5xr&0%2I0RSc+1a|-c literal 0 HcmV?d00001 diff --git a/tests/fixtures/mlg-11-9-26/BE8081.MLG b/tests/fixtures/mlg-11-9-26/BE8081.MLG new file mode 100644 index 0000000000000000000000000000000000000000..dceb43b6ea34a836a442586662933053f0f1c3f6 GIT binary patch literal 1186 zcmWe&U~FJu@XRYNNz5xr&0%2IQDWpofxmp-l7-EqaaYEL-z%XhMV0y&Pz|Sua z^Zx(;3=D`c3MtA=PfsmU@JTI8%~7yY@W?DK$xkmz%!Mf*<}~9{q%cx|hLxcr0|N^p zj5wgeh``|;=AnY>y;Ye=VWbZWBSr=$q;v!eBYpSOd@BV5J!1m{h0HwtV&1USq7q~Q LRHKIt&)5L~39B!Y literal 0 HcmV?d00001 diff --git a/tests/fixtures/mlg-11-9-26/BE8081321.MLG b/tests/fixtures/mlg-11-9-26/BE8081321.MLG new file mode 100644 index 0000000000000000000000000000000000000000..e556fb1ae1e18654cef673ccefa510ca82280761 GIT binary patch literal 2062 zcmWe&U~FJu@XRYNNz5xr&0%2IQDWpofxmp-l7-EqaaYEL-z%XjyVR_8XASh@J z^Zx(;3=D`c3MtA=PfsmU@JTI8%~7yY@W?DK$xkmz%!Mf*=JefIL>LJ%fWt~ikwKAx zfdvsp9FQOsVt@w@?=TM)RPS9Vf`^fi8XrtqijKw-oWNofxmuc-7-EqaaYARxfnn4j#r2AvL4ZvO z=KcTw85j^@6jGF#o}OBy;FDUGnq#Hlky%`lpI(%h3sXJZX}*a_VWbQRD|S(41_l;H z7;!*@P#GRNyu&?MQ2f`dh7?As(7-Tfrw4kIB`Q&ueL2q-;5)6s@C05i-y7XSbN literal 0 HcmV?d00001 diff --git a/tests/test_mlg_file.py b/tests/test_mlg_file.py new file mode 100644 index 0000000..a7fd7de --- /dev/null +++ b/tests/test_mlg_file.py @@ -0,0 +1,110 @@ +""" +Tests for minimateplus/mlg_file.py — Blastware's monitor log (.MLG) reader and writer. + +Fixtures (tests/fixtures/mlg-11-9-26/) are real files: DL2's ACH folder +(BE12844, BE6907 from 2026; BE8081 from 2018-19) and three bench files. +Expected values come from an independent scratch parser that was checked +against DL2's event-file footers (785 / 785 BE8081 records matched by stop, +flag word and trigger source), never from the code under test. Format: +docs/instantel_protocol_reference.md D.4, spec +docs/superpowers/specs/2026-11-09-mlg-unit-timeline-design.md. +""" + +from __future__ import annotations + +import datetime +import os +import sys +from pathlib import Path + +import pytest + +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +from minimateplus.crc import crc16_aug_ccitt +from minimateplus.mlg_file import MlgFormatError, parse_mlg, read_mlg + +FIX = Path(__file__).parent / "fixtures" / "mlg-11-9-26" +dt = datetime.datetime + + +def test_crc_matches_the_micromate_rule(): + from micromate.setup_block import _crc16_aug_ccitt + assert crc16_aug_ccitt(b"123456789") == _crc16_aug_ccitt(b"123456789") == 0xE5CC + + +def test_every_fixture_record_passes_its_checksum(): + files = sorted(FIX.glob("*.MLG")) + assert len(files) == 12 + for p in files: + assert parse_mlg(p.read_bytes()).crc_failures == [], p.name + + +def test_closed_records(): + m = read_mlg(FIX / "BE128443065.MLG") + assert m.serial == "BE12844" and len(m.records) == 2 + r1, r2 = m.records + assert (r1.index, r1.start, r1.stop, r1.flags, r1.trigger_source) == ( + 1, dt(2026, 9, 5, 18, 47, 26), dt(2026, 9, 5, 20, 0, 0), 0x0010, 0) + assert r1.description == "Timer Stop" + assert r1.trigger_level == "Geo: 0.0500 in/s Mic: 125.0 dB(L)" + assert r1.serial == "BE12844" + assert (r2.start, r2.stop, r2.description) == ( + dt(2026, 9, 6, 6, 0, 13), dt(2026, 9, 6, 18, 45, 0), "Modem Exit") + + +def test_monitoring_started_and_an_event(): + m = read_mlg(FIX / "BE128443067.MLG") + start, ev = m.records[1], m.records[2] + assert start.is_start and start.stop is None + assert start.description == "Monitoring started" + assert start.trigger_level == "Geo: 0.0500 in/s Mic: 125.0 dB(L)" + assert (ev.flags, ev.trigger_source, ev.description) == (0x0001, 0x0001, "Event Recorded") + assert ev.event_time == dt(2026, 9, 8, 13, 38, 22) + assert ev.text == "Geo: 0.0500 in/s Mic: 125.0 dB(L)\rTran: 0.0500 in/s" + assert ev.trigger_level == "Geo: 0.0500 in/s Mic: 125.0 dB(L)" + + +def test_histogram_with_a_waveform_event(): + r = read_mlg(FIX / "BE8081.MLG").records + assert (r[1].flags, r[1].trigger_source, r[1].description) == ( + 0x0021, 0x0400, "Event Recorded Modem Exit") + assert r[1].trigger_level == "Histogram" + assert (r[2].trigger_source, r[2].trigger_level) == (0x0002, "Geo: 0.300 in/s") + + +def test_trigger_level_with_or_without_a_space_before_the_colon(): + a = read_mlg(FIX / "BE11529.MLG").records[0] + b = read_mlg(FIX / "BE115292.MLG").records[0] + assert a.text == "Trigger Level: Histogram" and b.text == "Trigger Level : Histogram" + assert a.trigger_level == b.trigger_level == "Histogram" + + +def test_empty_file(): + m = read_mlg(FIX / "BE6907751.MLG") + assert m.serial is None and m.records == [] and m.empty + + +def test_a_flipped_byte_fails_only_its_record(): + data = bytearray((FIX / "BE128443065.MLG").read_bytes()) + data[18 + 292 + 40] ^= 0xFF # inside record 1's text + m = parse_mlg(bytes(data)) + assert m.crc_failures == [1] + assert m.records[0].crc_ok is False and m.records[1].crc_ok is True + + +def test_a_flipped_byte_in_the_header_record_is_reported(): + data = bytearray((FIX / "BE128443065.MLG").read_bytes()) + data[18 + 100] ^= 0xFF # inside the header record's zero area + assert parse_mlg(bytes(data)).crc_failures == [0] + + +@pytest.mark.parametrize("mangle", [ + lambda d: d[:-1], # not 18 + 292·n + lambda d: b"\x00" + d[1:], # wrong prefix + lambda d: d[:18] + b"\x23" + d[19:], # header length field not 290 + lambda d: d[:6], # shorter than the prefix +], ids=["not-whole", "prefix", "length-field", "short"]) +def test_structure_errors_raise(mangle): + with pytest.raises(MlgFormatError): + parse_mlg(mangle((FIX / "BE128443065.MLG").read_bytes()))