REPOSITORY CODING · MEDIUM
Decode signed little-endian sensor samples
Packet checksums pass, but sample values swap bytes and lose their sign. Repair sample decoding, including the signed extrema, while preserving header/trailer byte order.
Runtime DiagnosticsBinary packet inspection laboratory
Work through a real codebase.
Choose an environment, investigate the existing implementation and use the tests to check your change. Sign in to open a workspace; execution and Ono usage follow your plan’s allowances.
Task requirements and environments
C++ · 55 minute session
- Decode a bounded stream of hexadecimal chunks. Each frame has magic CA FE, a two-byte big-endian payload length, that many payload bytes, and a two-byte big-endian CRC-16/CCITT-FALSE trailer. Payload length is even and at most 512 bytes. CRC starts at FFFF, uses polynomial 1021, and covers the complete header and payload, excluding the trailer.
- Payload values are signed 16-bit little-endian samples. Decode two-complement values without relying on implementation-defined narrowing. Return packets in stream order with samples, payloadBytes and the verified checksum.
- Chunk boundaries are transport boundaries, not frame boundaries. Retain an incomplete header, payload or trailer for the next chunk; drain every complete frame exactly once. Empty chunks are harmless. Final residual bytes are a truncated-frame error. A malformed frame rejects the complete request rather than exposing a partial packet list.
- Accept uppercase or lowercase hex, reject odd-length chunks and nonhex characters. Bound the batch to 128 chunks, 8192 decoded bytes and 128 packets. This is an offline binary protocol rehearsal; it opens no network socket beyond the local preview.
- Summarize only verified packets: frame count, sample count, signed sum and minimum/maximum, with null extrema for no samples. A rejected stream exposes no partial summary.