Skip to content

Commit

Permalink
Add ComputeOnMiss Interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierHecart committed Feb 16, 2024
1 parent b4564a2 commit d3c6700
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions zenoh/src/net/routing/interceptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,44 @@ impl InterceptorTrait for InterceptorsChain {
}
}

pub(crate) struct ComputeOnMiss<T: InterceptorTrait> {
interceptor: T,
}

impl<T: InterceptorTrait> ComputeOnMiss<T> {
#[allow(dead_code)]
pub(crate) fn new(interceptor: T) -> Self {
Self { interceptor }
}
}

impl<T: InterceptorTrait> InterceptorTrait for ComputeOnMiss<T> {
#[inline]
fn compute_keyexpr_cache(&self, key_expr: &KeyExpr<'_>) -> Option<Box<dyn Any + Send + Sync>> {
self.interceptor.compute_keyexpr_cache(key_expr)
}

#[inline]
fn intercept<'a>(
&self,
ctx: RoutingContext<NetworkMessage>,
cache: Option<&Box<dyn Any + Send + Sync>>,
) -> Option<RoutingContext<NetworkMessage>> {
if cache.is_some() {
self.interceptor.intercept(ctx, cache)
} else if let Some(key_expr) = ctx.full_key_expr() {
self.interceptor.intercept(
ctx,
self.interceptor
.compute_keyexpr_cache(&key_expr.into())
.as_ref(),
)
} else {
self.interceptor.intercept(ctx, cache)
}
}
}

pub(crate) struct IngressMsgLogger {}

impl InterceptorTrait for IngressMsgLogger {
Expand Down

0 comments on commit d3c6700

Please sign in to comment.