1use std::{fmt::Display, collections::HashMap};
2
3pub const TITLE_NAMES: [&str; 17] = ["timeStamp", "elapsed", "label", "responseCode", "responseMessage", "threadName", "dataType", "success", "failureMessage", "bytes", "sentBytes", "grpThreads", "allThreads", "URL", "Latency", "IdleTime", "Connect"];
4
5#[derive(Clone)]
6pub struct RecordData {
7 time_stamp: u128,
8 elapsed: u64,
9 label: String,
10 response_code: u16,
11 response_message: String,
12 thread_name: String,
13 data_type: String,
14 success: bool,
15 failure_message: Option<String>,
16 bytes: u64,
17 sent_bytes: u64,
18 grp_threads: u32,
19 all_threads: u32,
20 url: String,
21 latency: u64,
22 idle_time: u64,
23 connect: u64,
24 response_result: Option<ResponseResult>,
25}
26
27#[derive(Clone)]
28pub struct ResponseResult {
29 response_headers: HashMap<String, String>,
30 response_data: String,
31}
32
33impl ResponseResult {
34 pub fn new(response_headers: HashMap<String, String>, response_data: String) -> Self {
35 Self { response_headers, response_data }
36 }
37
38 pub fn get_headers(&self) -> HashMap<String, String> {
39 self.response_headers.clone()
40 }
41
42 pub fn get_response_data(&self) -> String {
43 self.response_data.clone()
44 }
45}
46
47impl RecordData {
48 pub fn new(
49 time_stamp: u128,
50 elapsed: u64,
51 label: String,
52 response_code: u16,
53 response_message: String,
54 thread_name: String,
55 data_type: String,
56 success: bool,
57 failure_message: Option<String>,
58 bytes: u64,
59 sent_bytes: u64,
60 grp_threads: u32,
61 all_threads: u32,
62 url: String,
63 latency: u64,
64 idle_time: u64,
65 connect: u64,
66 response_result: Option<ResponseResult>,
67 ) -> Self {
68 Self {
69 time_stamp,
70 elapsed,
71 label,
72 response_code,
73 response_message,
74 thread_name,
75 data_type,
76 success,
77 failure_message,
78 bytes,
79 sent_bytes,
80 grp_threads,
81 all_threads,
82 url,
83 latency,
84 idle_time,
85 connect,
86 response_result,
87 }
88 }
89
90 pub fn thread_name(&mut self, thread_name: String) {
91 self.thread_name = thread_name;
92 }
93
94 pub fn grp_threads(&mut self, grp_threads: u32) {
95 self.grp_threads = grp_threads;
96 }
97
98 pub fn all_threads(&mut self, all_threads: u32) {
99 self.all_threads = all_threads;
100 }
101
102 pub fn get_response_result(&self) -> Option<ResponseResult> {
103 self.response_result.clone()
104 }
105}
106
107impl Display for RecordData {
108 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
109 write!(
110 f,
111 "{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}",
112 self.time_stamp,
113 self.elapsed,
114 self.label,
115 self.response_code,
116 self.response_message,
117 self.thread_name,
118 self.data_type,
119 self.success,
120 self.failure_message.clone().unwrap_or("".to_string()),
121 self.bytes,
122 self.sent_bytes,
123 self.grp_threads,
124 self.all_threads,
125 self.url,
126 self.latency,
127 self.idle_time,
128 self.connect,
129 )
130 }
131}