Expand description
Protocol translation framework (DW-100).
The gateway can sit between clients and upstreams that speak different
protocols and translate the request and response bodies on the fly.
This module defines the shared, protocol-agnostic seam every
translator implements: the ProtocolTranslator trait, the
TranslatedRequest / TranslatedResponse carrying the converted
bytes, the TranslationError enum, and a TranslationRegistry
that maps content-type pairs to translators.
§Translators
Three translators compile into every build (no cargo features):
- REST <-> gRPC (DW-101, shared): the gRPC-Web transcoding engine
in
super::grpc_webalready translates JSON <-> protobuf; this seam reuses it through the shared trait. - REST <-> GraphQL (
super::translation_graphql): translates a REST JSON body to a GraphQL query using a config-supplied query template, and a GraphQL response back to a REST JSON body. - SOAP/XML (
super::translation_soap): translates SOAP XML envelopes to REST JSON and back, using a minimal hand-rolled XML parser (no external XML crate, to avoid deny.toml review and binary size).
§Why a shared trait
Every translator does the same two things on a route: convert the inbound request body to the upstream’s wire format, and convert the upstream’s response body back to the client’s wire format. Factoring that into one trait lets the dataplane dispatch by content-type pair through a single registry, and lets a new translator (e.g. a future Thrift or AMQP bridge) plug in without touching the request path.
§Feature gating
This module compiles only when the protocol_translation cargo
feature is enabled. The config schema (Translation,
TranslationKind, GraphqlTranslation, SoapTranslation) is always
present so configs round-trip without the feature; when the feature
is off the block is accepted but inert (validation warns, the runtime
translation does not run). The SOAP translator is further gated
behind the soap feature for binary size.
Structs§
- Translated
Request - The converted request to send upstream: the method, path, headers, and body the translator produced from the inbound request.
- Translated
Response - The converted response to send the client: the status, headers, and body the translator produced from the upstream response.
- Translation
Body - A complete, buffered body used by the translation seam.
- Translation
Registry - A registry of protocol translators keyed by the (in, out) content-type
pair. Built at config publish; held behind an
Arcby the request path. A route’stranslation.kindresolves to one entry here.
Enums§
- Translation
Error - Errors from protocol translation.
Traits§
- Protocol
Translator - Translate a request/response pair between two wire protocols.