FFORGE//RS
← Roadmap

rust / LEVEL 4

The parser that copied every packet

EST.50 MIN
01

THEORY / RETRIEVAL

What to restore

  • Tie parsed text and payload views to the input buffer lifetime
  • Validate every declared length before taking a slice
  • Prove zero-copy behavior with pointer ranges and an allocation counter

Zero-copy is an ownership decision

A parser can return `&str` and `&[u8]` views into the original packet instead of allocating String and Vec fields. The output lifetime then prevents the packet buffer from being reused or dropped too early. This trades allocation and copying for a more explicit buffer-lifetime contract.

Validate structure before borrowing regions

Read the fixed header only after checking its size, apply protocol limits, compute the exact frame length with checked arithmetic, and only then slice. `str::from_utf8` validates text while returning a borrowed `&str`; unsafe unchecked conversion is unnecessary unless profiling proves the check redundant under a stronger invariant.

CHECKPOINT

Which properties are required for a safe zero-copy binary-frame parser?

Select every applicable option. Credit requires an exact set match.

ISOLATED RUST 1.96
src/lib.rsEDIT

02 / PROFILING

Read the profile and fix the cause

Refactor `Frame` and `parse_frame` so topic, key and payload borrow directly from the input. Keep the protocol and error taxonomy, reject trailing or truncated bytes, use checked UTF-8, and perform zero heap allocations on a valid frame.

Initializing editor…
CLOUD SANDBOXnetwork off · 256 MB · 12 s
2 / 64 KB
OUTPUT
Runner is waiting for a submission.