"""Binary payload serialization for sweep/result collections.""" from __future__ import annotations import struct import numpy as np from python_app.models.dataset_model import ResultCollection, SweepCollection RAW_MAGIC = 0x32574152 PREPROC_MAGIC = 0x32525050 RESULT_MAGIC = 0x324C5352 # RSL2: adds processing_duration_ns after monotonic_ns def _write_interleaved_complex(buffer: bytearray, values: np.ndarray) -> None: """Append complex64 array as interleaved float32 real/imag pairs.""" interleaved = np.empty(values.size * 2, dtype=" bytes: """Serialize one raw/preprocessed trace collection into ring-compatible binary format. The trailer is appended after the trace blocks so older readers, which stop at the last block, still decode the traces: first the collection capture window, then a per-trace window table (one ``(start_ns, end_ns)`` pair per trace, in trace order). See :func:`python_app.orchestration.shm.decoder.decode_trace_collection` and ``read_trace_collection`` in ``common_cpp/ipc/src/shared_types.cpp``. """ buffer = bytearray() buffer.extend(struct.pack(" bytes: """Serialize one processed collection with result blocks/payloads.""" def serialize_payload(buffer: bytearray, payload) -> None: """Append one payload in ring-compatible result format.""" name_bytes = payload.processing_name.encode("utf-8") if len(name_bytes) > 0xFFFF: raise ValueError("processing_name is too long") buffer.extend(struct.pack("