pub fn encode_data_response(
response: &DataResponse,
) -> Result<EncodedPayload, EncodeError>Expand description
Encodes a [DataResponse] envelope by dispatching on the variant.
send_data_response hands the bus tap a [DataResponse] wrapper, so the tap
dispatches by the wrapper’s std::any::TypeId and the inner variants never reach
their bare-type encoders. The dispatcher unwraps each variant, encodes the inner
struct, and stamps the inner-variant tag so forensics scans see entries identical
to a bare-type capture path.
Each variant carries a correlation_id (UUID4) pairing the response with the
originating RequestCommand::request_id. IndexKind has no matching variant
today, so every variant emits zero sidecar indices, mirroring the
[PositionStatusReport] and [AccountState] precedents.
The [DataResponse::Data] and [DataResponse::Book] variants carry payloads that
are not directly serializable: [CustomDataResponse] holds an Arc<dyn Any> and
[BookResponse] holds a [nautilus_model::orderbook::OrderBook] without serde
derives. The dispatcher serializes the audit-relevant metadata for those two
variants via local borrowed wrapper structs (the encode_order_with_fills
precedent) and omits the opaque payload. BookResponse is state-affecting on
the data engine path (handle_book_response clones the book into the cache); a
follow-up that adds serde to OrderBook/BookLadder can replace the metadata
wrapper with full payload capture without changing the dispatcher contract.
§Errors
Returns the inner encoder’s EncodeError when MessagePack rejects the inner
payload.