Expand description
MessageAdapter — cross-format-version message-to-command translation.
§Problem
A GPKE process started under FV2025-10-01 may still be in-flight when
FV2026-10-01 goes live. The counterparty begins sending APERAK messages
in the new AHB format before the process completes. The field that signals
acceptance may have moved (e.g. a new qualifier in BGM DE 1001), or an
additional mandatory DTM has been added.
Without an explicit adapter, each workflow handles this ad-hoc inside its command constructor, making the mapping invisible, untested, and easy to forget when a new release cycle arrives.
§Solution
MessageAdapter<W> is the type-system home for all format-version-specific
translation logic. An adapter declares which format versions it can handle
(accepts_format_version), receives a parsed AnyMessage, and returns the
domain command to dispatch.
Adapters are registered in an AdapterRegistry at engine startup. The
registry validates at registration time that all format versions in the
workflow’s WorkflowVersionPolicy have a registered adapter.
§Example
use mako_engine::message_adapter::{AdapterRegistry, MessageAdapter};
use mako_engine::version::FormatVersion;
use mako_engine::error::EngineError;
struct GpkeAperakAdapter;
impl MessageAdapter<GpkeWorkflow> for GpkeAperakAdapter {
fn accepts_format_version(&self, fv: &FormatVersion) -> bool {
matches!(fv.as_str(), "FV2025-10-01" | "FV2026-10-01")
}
fn adapt(
&self,
msg: &dyn std::any::Any,
fv: &FormatVersion,
) -> Result<GpkeCommand, EngineError> {
// parse `msg` as APERAK and construct the appropriate command
Ok(GpkeCommand::ReceiveAperak { positive: true })
}
}
let mut registry: AdapterRegistry<GpkeWorkflow> = AdapterRegistry::new();
registry.register(GpkeAperakAdapter);Structs§
- Adapter
Registry - Runtime registry of
MessageAdapters for a single workflow typeW. - FnAdapter
- A simple function-based adapter constructed via
FnAdapter::new.
Traits§
- Message
Adapter - Translates a parsed EDIFACT message into a domain command for workflow
W.