Сравнение заявленной длины двоичного полезного груза перед возвратом его байтов
DEV · 17.11.2026 · 00:00
Разбор заголовка подтверждает его соответствие, но не гарантирует, что остальная часть сообщения имеет заявленную длину. Парсеру необходимо принимать явные решения в таких случаях перед…
Оригинал
Match a Declared Binary Payload Length Before Returning Its Bytes
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