use super::{DispatchTable, HandlerId, SpanAttributeProcessor};
use crate::xray_exporter::translator::{error::Result, AnyDocumentBuilder};
use opentelemetry::Value;
mod aws_operation_builder;
mod aws_xray_sdk_builder;
mod beanstalk_deployment_id_builder;
mod cause_builder;
mod cloudwatch_log_group_builder;
mod http_request_url_builder;
mod http_response_content_length_builder;
mod segment_name_builder;
mod segment_origin_builder;
mod sql_url_builder;
mod subsegment_namespace_builder;
pub(in crate::xray_exporter::translator) use aws_operation_builder::AwsOperationBuilder;
pub(in crate::xray_exporter::translator) use aws_xray_sdk_builder::AwsXraySdkBuilder;
pub(in crate::xray_exporter::translator) use beanstalk_deployment_id_builder::BeanstalkDeploymentIdBuilder;
pub(in crate::xray_exporter::translator) use cause_builder::CauseBuilder;
pub(in crate::xray_exporter::translator) use cloudwatch_log_group_builder::CloudwatchLogGroupBuilder;
pub(in crate::xray_exporter::translator) use http_request_url_builder::HttpRequestUrlBuilder;
pub(in crate::xray_exporter::translator) use http_response_content_length_builder::HttpResponseContentLengthBuilder;
pub(in crate::xray_exporter::translator) use segment_name_builder::SegmentNameBuilder;
pub(in crate::xray_exporter::translator) use segment_origin_builder::SegmentOriginBuilder;
pub(in crate::xray_exporter::translator) use sql_url_builder::SqlUrlBuilder;
pub(in crate::xray_exporter::translator) use subsegment_namespace_builder::SubsegmentNamespaceBuilder;
pub(in super::super) trait ValueBuilder<'value> {
fn resolve(self, segment_builder: &mut AnyDocumentBuilder<'value>) -> Result<()>;
}
macro_rules! count_tts {
() => { 0 };
($odd:tt $($a:tt $b:tt)*) => { (count_tts!($($a)*) << 1) | 1 };
($($a:tt $even:tt)*) => { count_tts!($($a)*) << 1 };
}
macro_rules! any_builder_enum {
($($module:ident :: $variant:ident $(:: <$lt:lifetime>)? , )*) => {
#[allow(clippy::enum_variant_names)]
#[derive(Debug)]
pub(in super::super) enum AnyValueBuilder<'v> {
$($variant($module::$variant$(<$lt>)?),)*
}
impl<'v> AnyValueBuilder<'v> {
#[inline(always)]
pub fn process(&mut self, handler_index: HandlerId, value: &'v Value) -> bool {
match self {
$(
Self::$variant(builder) => $module::$variant::HANDLERS[handler_index].1(builder, value),
)*
}
}
pub const fn count() -> usize {
count_tts!($($module)*)
}
pub fn register_builders(dp: &mut DispatchTable) {
let mut processor_id = 0;
$(
processor_id += 1;
dp.register::<
{
const fn __len<T, const N: usize>(_: &[T; N]) -> usize { N }
__len(&$module::$variant::HANDLERS)
},
$module::$variant
>(processor_id - 1);
)*
}
#[allow(clippy::too_many_arguments)]
#[inline(always)]
pub fn array($($module: $module::$variant$(<$lt>)?),*) -> [Self; count_tts!($($module)*)] {
[
$(Self::$variant($module)),*
]
}
}
impl<'v> ValueBuilder<'v> for AnyValueBuilder<'v> {
fn resolve(self, segment_builder: &mut AnyDocumentBuilder<'v>) -> Result<()> {
match self {
$(
Self::$variant(builder) => builder.resolve(segment_builder),
)*
}
}
}
};
}
any_builder_enum!(
aws_operation_builder::AwsOperationBuilder::<'v>,
aws_xray_sdk_builder::AwsXraySdkBuilder::<'v>,
beanstalk_deployment_id_builder::BeanstalkDeploymentIdBuilder::<'v>,
cause_builder::CauseBuilder::<'v>,
cloudwatch_log_group_builder::CloudwatchLogGroupBuilder::<'v>,
http_request_url_builder::HttpRequestUrlBuilder::<'v>,
http_response_content_length_builder::HttpResponseContentLengthBuilder,
segment_name_builder::SegmentNameBuilder::<'v>,
segment_origin_builder::SegmentOriginBuilder::<'v>,
sql_url_builder::SqlUrlBuilder::<'v>,
subsegment_namespace_builder::SubsegmentNamespaceBuilder,
);