pub struct MessageTransformer { /* private fields */ }Expand description
Registry of named transformation pipelines.
§Example
use oxirs_stream::message_transformer::*;
use std::collections::HashMap;
let mut transformer = MessageTransformer::new();
let pipeline = TransformPipeline::new(
MessageFormat::Json,
MessageFormat::Avro,
vec![FieldMapping::with_transform("name", "NAME", TransformFn::ToUpper)],
);
transformer.add_pipeline("upper", pipeline);
let mut fields = HashMap::new();
fields.insert("name".to_string(), "alice".to_string());
let payload = MessagePayload::new(fields, MessageFormat::Json);
let result = transformer.transform("upper", payload)?;
assert_eq!(result.fields["NAME"], "ALICE");Implementations§
Source§impl MessageTransformer
impl MessageTransformer
Sourcepub fn add_pipeline(&mut self, name: &str, pipeline: TransformPipeline)
pub fn add_pipeline(&mut self, name: &str, pipeline: TransformPipeline)
Register a named pipeline. Overwrites any existing pipeline with the same name.
Sourcepub fn transform(
&self,
pipeline_name: &str,
payload: MessagePayload,
) -> Result<MessagePayload, TransformError>
pub fn transform( &self, pipeline_name: &str, payload: MessagePayload, ) -> Result<MessagePayload, TransformError>
Apply the named pipeline to payload.
Each FieldMapping in the pipeline is applied in order:
- The value of
source_fieldis read from the payload. - The optional
TransformFnis applied. - The result is stored under
target_fieldin the output payload.
Fields present in the payload but not mentioned by any mapping are dropped.
Sourcepub fn chain_pipelines(
&self,
names: &[&str],
payload: MessagePayload,
) -> Result<MessagePayload, TransformError>
pub fn chain_pipelines( &self, names: &[&str], payload: MessagePayload, ) -> Result<MessagePayload, TransformError>
Apply a sequence of pipelines in order.
The output of each pipeline is fed as the input to the next. The format of the intermediate payloads is updated by each pipeline.
Sourcepub fn list_pipelines(&self) -> Vec<&str>
pub fn list_pipelines(&self) -> Vec<&str>
Return the names of all registered pipelines (order unspecified).
Sourcepub fn pipeline_count(&self) -> usize
pub fn pipeline_count(&self) -> usize
Return the number of registered pipelines.
Sourcepub fn has_pipeline(&self, name: &str) -> bool
pub fn has_pipeline(&self, name: &str) -> bool
Check whether a pipeline with the given name exists.
Sourcepub fn remove_pipeline(&mut self, name: &str) -> bool
pub fn remove_pipeline(&mut self, name: &str) -> bool
Remove a pipeline by name. Returns true if it was present.
Trait Implementations§
Source§impl Debug for MessageTransformer
impl Debug for MessageTransformer
Source§impl Default for MessageTransformer
impl Default for MessageTransformer
Source§fn default() -> MessageTransformer
fn default() -> MessageTransformer
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for MessageTransformer
impl RefUnwindSafe for MessageTransformer
impl Send for MessageTransformer
impl Sync for MessageTransformer
impl Unpin for MessageTransformer
impl UnsafeUnpin for MessageTransformer
impl UnwindSafe for MessageTransformer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.