Unpacking a header establishes that the header fits. It does not establish that the rest of a message has the declared length, that a version is supported, or that trailing data is acceptable. A parser needs explicit decisions for those cases before returning a payload to its caller.
The invented frame below contains a two-byte marker, one version byte and an unsigned two-byte payload length. The struct reference distinguishes unpack, which requires an exact buffer size, from unpack_from, which reads a structure within a larger buffer. The exclamation-mark prefix chooses a network-order layout with standard sizes rather than a native-layout assumption.
Keep header decoding and frame validation separate
The parser accepts immutable bytes already in memory. It checks the marker, version, declared budget and exact total size.…