use std::collections::HashMap;
use re_log_types::{ApplicationId, RecordingId, StoreId, StoreInfo, StoreKind};
use re_protos::common::v1alpha1::ext::StoreIdMissingApplicationIdError;
pub trait ApplicationIdInjector {
fn store_info_received(&mut self, store_info: &StoreInfo);
fn recover_store_id(&self, store_id_err: StoreIdMissingApplicationIdError) -> Option<StoreId>;
}
#[derive(Default)]
pub struct CachingApplicationIdInjector(HashMap<(RecordingId, StoreKind), ApplicationId>);
impl ApplicationIdInjector for CachingApplicationIdInjector {
fn store_info_received(&mut self, store_info: &StoreInfo) {
self.0.insert(
(
store_info.recording_id().clone(),
store_info.store_id.kind(),
),
store_info.application_id().clone(),
);
}
fn recover_store_id(&self, store_id_err: StoreIdMissingApplicationIdError) -> Option<StoreId> {
let StoreIdMissingApplicationIdError {
store_kind,
recording_id,
} = store_id_err;
self.0
.get(&(recording_id.clone(), store_kind))
.cloned()
.map(|app_id| StoreId::new(store_kind, app_id, recording_id))
}
}
pub struct DummyApplicationIdInjector {
application_id: ApplicationId,
}
impl DummyApplicationIdInjector {
pub fn new(application_id: impl Into<ApplicationId>) -> Self {
Self {
application_id: application_id.into(),
}
}
}
impl ApplicationIdInjector for DummyApplicationIdInjector {
fn store_info_received(&mut self, _store_info: &StoreInfo) {
}
fn recover_store_id(&self, store_id_err: StoreIdMissingApplicationIdError) -> Option<StoreId> {
Some(StoreId::new(
store_id_err.store_kind,
self.application_id.clone(),
store_id_err.recording_id,
))
}
}