pub mod backends;
mod config;
mod environment;
mod errs;
mod event_loop;
mod heartbeat_rule;
mod resend_request_range;
mod seq_numbers;
#[cfg(feature = "utils-tokio")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "utils-tokio")))]
pub mod tokio_connection;
#[cfg(feature = "utils-tokio")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "utils-tokio")))]
pub mod tokio_event_loop;
use crate::tagvalue::Message;
use crate::{FieldType, SetField};
pub use config::{Config, Configure};
pub use environment::Environment;
pub use event_loop::*;
pub use heartbeat_rule::HeartbeatRule;
pub use resend_request_range::ResendRequestRange;
pub use seq_numbers::{SeqNumberError, SeqNumbers};
use std::ops::Range;
pub trait Backend: Clone {
type Error: for<'a> FieldType<'a>;
fn sender_comp_id(&self) -> &[u8];
fn target_comp_id(&self) -> &[u8];
fn message_encoding(&self) -> Option<&[u8]> {
None
}
fn set_sender_and_target(&self, msg: &mut impl SetField<u32>) {
msg.set(49, self.sender_comp_id());
msg.set(56, self.target_comp_id());
}
fn environment(&self) -> Environment {
Environment::Production { allow_test: false }
}
fn on_heartbeat_is_due(&mut self) -> Result<(), Self::Error> {
Ok(())
}
fn on_inbound_app_message(
&mut self,
message: Message<&[u8]>,
) -> Result<(), Self::Error>;
fn on_outbound_message(
&mut self,
message: &[u8],
) -> Result<(), Self::Error>;
fn on_inbound_message(
&mut self,
message: Message<&[u8]>,
is_app: bool,
) -> Result<(), Self::Error> {
if is_app { self.on_inbound_app_message(message) } else { Ok(()) }
}
fn on_resend_request(
&mut self,
range: Range<u64>,
) -> Result<(), Self::Error>;
fn on_successful_handshake(&mut self) -> Result<(), Self::Error>;
fn fetch_messages(&mut self) -> Result<&[&[u8]], Self::Error>;
fn pending_message(&mut self) -> Option<&[u8]>;
}
#[derive(Debug, Clone)]
pub struct State {
#[allow(dead_code)] next_inbound: u64,
#[allow(dead_code)] next_outbound: u64,
}
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct MsgSeqNumCounter(u64);
impl MsgSeqNumCounter {
pub const START: Self = Self(0);
pub fn next(&mut self) -> u64 {
self.0 += 1;
self.0
}
pub fn expected(&self) -> u64 {
self.0 + 1
}
}
impl Iterator for MsgSeqNumCounter {
type Item = u64;
fn next(&mut self) -> Option<Self::Item> {
Some(MsgSeqNumCounter::next(self))
}
}
#[derive(Debug)]
pub struct FixConnection;