From d3c6700193115425c6fdf01c8454e9a41f6da297 Mon Sep 17 00:00:00 2001 From: OlivierHecart Date: Fri, 16 Feb 2024 15:58:45 +0100 Subject: [PATCH] Add ComputeOnMiss Interceptor --- zenoh/src/net/routing/interceptor/mod.rs | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/zenoh/src/net/routing/interceptor/mod.rs b/zenoh/src/net/routing/interceptor/mod.rs index acc3e57013..9dfc03ac7e 100644 --- a/zenoh/src/net/routing/interceptor/mod.rs +++ b/zenoh/src/net/routing/interceptor/mod.rs @@ -116,6 +116,44 @@ impl InterceptorTrait for InterceptorsChain { } } +pub(crate) struct ComputeOnMiss { + interceptor: T, +} + +impl ComputeOnMiss { + #[allow(dead_code)] + pub(crate) fn new(interceptor: T) -> Self { + Self { interceptor } + } +} + +impl InterceptorTrait for ComputeOnMiss { + #[inline] + fn compute_keyexpr_cache(&self, key_expr: &KeyExpr<'_>) -> Option> { + self.interceptor.compute_keyexpr_cache(key_expr) + } + + #[inline] + fn intercept<'a>( + &self, + ctx: RoutingContext, + cache: Option<&Box>, + ) -> Option> { + 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 {