Convert two-character hexadecimal tokens into ordered byte values without interpreting them as text. Work only with supplied input; this does not contact external services or modify input.
Before you start
- Save as recipe.rs and compile with Rust 1.99.0 using: rustc --edition=2021 recipe.rs -o recipe
- Run ./recipe with input supplied through stdin. No CLI arguments are accepted, including help flags.
- Reads at most 65537 bytes and rejects input exceeding 65536 bytes. Requires strict UTF-8, rejects a leading UTF-8 BOM, and rejects every CR.
- Splits only at LF and discards exactly empty segments. Before token classification, enforces at most 100 nonempty lines and at most 256 UTF-8 bytes per retained line. No trimming or normalization occurs.
- Each retained line must be exactly two lowercase ASCII hexadecimal digits. Preserves order and duplicates, converting tokens into integer byte values without interpreting decoded bytes as text.
- Empty input or input consisting only of LF characters produces {"bytes":[]}. Successful output is one JSON object followed by a newline, with exit status 0 and no stderr.
- All input validation completes before successful stdout is written. Invalid arguments, invalid input, and stdin-read failures produce no stdout, exit 2, and write exactly error: invalid input followed by a newline to stderr, subject to the output-failure limitation below.
- Uses only the standard library and permitted APIs; no Cargo, external crates, filesystem access, networking, or subprocesses.
Build and check
- Save the example as recipe.rs.
- Compile with Rust 1.99.0 using rustc --edition=2021 recipe.rs -o recipe.
- Prepare UTF-8 input.txt following the documented operation-specific conventions.
- Run ./recipe < input.txt.
- Inspect the JSON result. Exit 2 with exactly error: invalid input followed by a newline on stderr and no stdout identifies rejected input or stdin-read failure. Output-write failures may also exit nonzero, without that diagnostic and potentially after partial stdout; these are outside the input-error guarantee.
Limits to understand
- Memory use is bounded by the 65537-byte input buffer, up to 100 borrowed line references and 100 decoded bytes, a JSON output buffer of at most 412 bytes, and standard-library buffering and allocation overhead.
- Reading stdin may block while waiting for data or EOF. Inputs of 65536 bytes or fewer require EOF to establish completion.
- Successful output contains decoded input values and may be sensitive. Error diagnostics never include input values.
- Memory-allocation failures and output-write failures are outside the input-error guarantee. Output-write failures may leave partial stdout or prevent the fixed stderr diagnostic from being delivered; detected stdout-write failures exit 2.
Run it
rustc --edition=2021 recipe.rs -o recipe
./recipe < input.txtExample input
00
ff
7f
00
Expected output
{"bytes":[0,255,127,0]}
