Skip to main content

Module payload

Module payload 

Source
Expand description

Record-payload generator.

The first 24 bytes of every produced record hold (magic_be, scenario_id_be, send_unix_nanos_be), so a consumer can compute the end-to-end latency when it re-reads the embedded send_unix_nanos. The remaining bytes are a deterministic filler, so the wire size is exactly the scenario’s message size.

The header is 24 bytes and not the 16 the plan sketched, because it needs a magic to detect “this is one of ours”. Kafka’s own producers leave their own headers in there, and this driver must not misread their bytes.

Constants§

HEADER_LEN
MAGIC
Magic prefix on every record, so a consumer can confirm that this driver produced the record and that it is not data already in the topic.

Functions§

key
Builds a record key of exactly key_size bytes, distinct per sequence.
read_send_nanos
Reads the embedded send_unix_nanos if the record is one of ours. Returns None if the magic does not match, and also if the record is too short. The consumer skips both cases silently.
stamp_into
Stamps the magic, the scenario_id, and the current unix_nanos into the first 24 bytes of buf. Returns the value as a Bytes, which the caller clones cheaply with a BytesMut::freeze-style copy.
template
Builds a reusable filler template of exactly msg_size bytes, or of the header length if that is larger.