-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapplication.rs
More file actions
59 lines (50 loc) · 1.75 KB
/
application.rs
File metadata and controls
59 lines (50 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::messages::{ExecutionReport, InboundMsg, OutboundMsg};
use hotfix::Application;
use hotfix::Message;
use hotfix::application::{InboundDecision, OutboundDecision};
use hotfix::session::Status;
use tokio::sync::mpsc::UnboundedSender;
use tracing::info;
pub struct LoadTestingApplication {
sender: UnboundedSender<ExecutionReport>,
}
impl LoadTestingApplication {
pub fn new(sender: UnboundedSender<ExecutionReport>) -> Self {
Self { sender }
}
}
#[async_trait::async_trait]
impl Application for LoadTestingApplication {
type Outbound = OutboundMsg;
async fn on_outbound_message(&self, _msg: &OutboundMsg) -> OutboundDecision {
OutboundDecision::Send
}
async fn on_inbound_message(&self, msg: &Message) -> InboundDecision {
let parsed = InboundMsg::parse(msg);
match parsed {
InboundMsg::Unimplemented(data) => {
let pretty_bytes: Vec<u8> = data
.iter()
.map(|b| if *b == b'\x01' { b'|' } else { *b })
.collect();
let s = std::str::from_utf8(&pretty_bytes).unwrap_or("invalid characters");
info!("received message: {:?}", s);
}
InboundMsg::ExecutionReport(report) => {
if self.sender.send(report).is_err() {
return InboundDecision::TerminateSession;
}
}
}
InboundDecision::Accept
}
async fn on_logout(&mut self, _reason: &str) {
info!("we've been logged out");
}
async fn on_logon(&mut self) {
info!("we've been logged in");
}
async fn on_state_change(&self, from: &Status, to: &Status) {
info!("we've changed from {:?} to {:?}", from, to);
}
}