use crate::{enums, fix};
use chrono::{DateTime, Utc};
pub trait Registry {
fn get_allowed_types_for_tag(&self, tag: &str) -> Vec<String>;
fn contains(&self, tag: &str) -> bool;
}
pub trait AllowedType<const TAG: u32, T> {}
#[macro_export]
macro_rules! fix_tag_registry {
($registry_name:ident { $( $tag:literal => [$($type:ty),+ $(,)?] ),* $(,)? } ) => {
pub struct $registry_name;
impl $crate::tag::Registry for $registry_name {
fn get_allowed_types_for_tag(&self, tag: &str) -> Vec<String> {
let parsed = tag.parse::<u32>();
match parsed.unwrap_or(0) {
$( $tag => vec![$(stringify!($type).to_string()),+], )*
_ => vec![]
}
}
fn contains(&self, tag: &str) -> bool {
let tag_val = tag.parse::<u32>().unwrap_or(0);
#[allow(unreachable_code)]
{
false $(|| tag_val == $tag)*
}
}
}
$( $(
impl $crate::tag::AllowedType<$tag, $type> for $registry_name {}
impl $crate::tag::AllowedType<$tag, Option<$type>> for $registry_name {}
)+ )*
impl<const TAG: u32> $crate::tag::AllowedType<TAG, String> for $registry_name {}
impl<const TAG: u32> $crate::tag::AllowedType<TAG, &str> for $registry_name {}
impl<const TAG: u32> $crate::tag::AllowedType<TAG, Option<String>> for $registry_name {}
impl<const TAG: u32> $crate::tag::AllowedType<TAG, Option<&str>> for $registry_name {}
};
($registry_name:ident) => {
$crate::fix_tag_registry!($registry_name {});
};
}
pub use crate::fix_tag_registry;
fix_tag_registry! {
DefaultRegistry {
9 => [u32], 6 => [f64, fix::Price], 14 => [f64], 31 => [f64, fix::Price], 32 => [f64], 34 => [u64, i64], 38 => [f64], 44 => [f64, fix::Price], 52 => [DateTime<Utc>], 99 => [f64, fix::Price], 132 => [f64, fix::Price], 133 => [f64, fix::Price], 140 => [f64, fix::Price], 141 => [u8, enums::ResetSeqNumFlag], 151 => [f64], 202 => [f64, fix::Price], 231 => [f64], 260 => [f64, fix::Price], 270 => [f64, fix::Price], 271 => [f64], 272 => [DateTime<Utc>], 393 => [u32], 810 => [f64, fix::Price], 1208 => [f64],
35 => [enums::MsgType], 20 => [enums::ExecTransType], 21 => [enums::HandlInst], 22 => [enums::SecurityIDSource], 39 => [enums::OrdStatus], 40 => [enums::OrdType], 54 => [enums::Side], 59 => [enums::TimeInForce], 150 => [enums::ExecType], 167 => [enums::SecurityType], 263 => [enums::SubscriptionRequestType], 205 => [u8, fix::DayOfMonth], 265 => [enums::MDUpdateType], 269 => [enums::MDEntryType], 279 => [enums::MDUpdateAction], 281 => [enums::MDReqRejReason], 314 => [u8, fix::DayOfMonth], 321 => [enums::SecurityRequestType], 323 => [enums::SecurityResponseType], 373 => [enums::SessionRejectReason],
10 => [u8], }
}