Skip to content

Commit 866d1be

Browse files
authored
feat: decouple hotfix session layer from FIX 4.4 (#257)
* Replace fix44 references with dedicated transport only fields * Add clippy without all targets and features to pipeline
1 parent e068dc2 commit 866d1be

31 files changed

Lines changed: 233 additions & 149 deletions

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
- name: Check formatting
1919
run: cargo fmt --check
2020
- name: Run clippy
21+
run: cargo clippy -- -Dclippy::all -D warnings
22+
- name: Run clippy (all targets and features)
2123
run: cargo clippy --all-targets --all-features -- -Dclippy::all -D warnings
2224
- name: Run tests
2325
run: cargo test --verbose

crates/hotfix-dictionary/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fix40 = []
1717
fix41 = []
1818
fix42 = []
1919
fix43 = []
20-
# FIX 4.4 is always enabled.
20+
fix44 = []
2121
fix50 = []
2222
fix50sp1 = []
2323
fix50sp2 = []

crates/hotfix-dictionary/src/dictionary.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ impl Dictionary {
110110
}
111111

112112
/// Creates a new [`Dictionary`] for FIX 4.4.
113+
#[cfg(feature = "fix44")]
113114
pub fn fix44() -> Self {
114115
let spec = include_str!("resources/quickfix/FIX-4.4.xml");
115116
Dictionary::from_quickfix_spec(spec).unwrap()
@@ -160,6 +161,7 @@ impl Dictionary {
160161
Self::fix42(),
161162
#[cfg(feature = "fix43")]
162163
Self::fix43(),
164+
#[cfg(feature = "fix44")]
163165
Self::fix44(),
164166
#[cfg(feature = "fix50")]
165167
Self::fix50(),

crates/hotfix-dictionary/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ pub type TagU32 = std::num::NonZeroU32;
3030
#[cfg(test)]
3131
mod test {
3232
use super::*;
33+
#[cfg(feature = "fix44")]
3334
use crate::layout::LayoutItemKind;
3435
use std::collections::HashSet;
3536

3637
#[test]
38+
#[cfg(feature = "fix44")]
3739
fn fix44_quickfix_is_ok() {
3840
let dict = Dictionary::fix44();
3941
let msg_heartbeat = dict.message_by_name("Heartbeat").unwrap();
@@ -77,6 +79,7 @@ mod test {
7779
}
7880

7981
#[test]
82+
#[cfg(feature = "fix44")]
8083
fn fix44_field_28_has_three_variants() {
8184
let dict = Dictionary::fix44();
8285
let field_28 = dict.field_by_tag(28).unwrap();
@@ -85,6 +88,7 @@ mod test {
8588
}
8689

8790
#[test]
91+
#[cfg(feature = "fix44")]
8892
fn fix44_field_36_has_no_variants() {
8993
let dict = Dictionary::fix44();
9094
let field_36 = dict.field_by_tag(36).unwrap();
@@ -93,6 +97,7 @@ mod test {
9397
}
9498

9599
#[test]
100+
#[cfg(feature = "fix44")]
96101
fn fix44_field_167_has_eucorp_variant() {
97102
let dict = Dictionary::fix44();
98103
let field_167 = dict.field_by_tag(167).unwrap();

crates/hotfix-message/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ categories.workspace = true
1313

1414
[features]
1515
fix42 = ["hotfix-dictionary/fix42"]
16+
fix44 = ["hotfix-dictionary/fix44"]
17+
1618
utils-chrono = []
1719

1820
[lints]
@@ -37,7 +39,7 @@ quickcheck_macros.workspace = true
3739

3840
[build-dependencies]
3941
hotfix-codegen = { version = "0.1.4", path = "../hotfix-codegen" }
40-
hotfix-dictionary = { version = "0.1.3", path = "../hotfix-dictionary", features = ["fix42"] }
42+
hotfix-dictionary = { version = "0.1.3", path = "../hotfix-dictionary", features = ["fixt11"] }
4143

4244
chrono.workspace = true
4345

crates/hotfix-message/build.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ use std::io::Write;
99
use std::path::PathBuf;
1010

1111
fn main() -> io::Result<()> {
12-
// TODO: add other FIX versions
1312
#[cfg(feature = "fix42")]
1413
codegen(Dictionary::fix42(), "fix42.rs")?;
15-
// FIX 4.4 is always enabled.
14+
#[cfg(feature = "fix44")]
1615
codegen(Dictionary::fix44(), "fix44.rs")?;
16+
17+
codegen(Dictionary::fixt11(), "fixt11.rs")?;
1718
Ok(())
1819
}
1920

crates/hotfix-message/src/encoding.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ pub mod field_types;
77
pub use buffer::{Buffer, BufferWriter};
88
pub use field_access::{FieldType, FieldValueError};
99

10+
pub use definitions::HardCodedFixFieldDefinition;
1011
#[cfg(feature = "fix42")]
1112
pub use definitions::fix42;
12-
pub use definitions::{HardCodedFixFieldDefinition, fix44};
13+
#[cfg(feature = "fix44")]
14+
pub use definitions::fix44;
15+
pub use definitions::fixt11;

crates/hotfix-message/src/encoding/definitions.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,17 @@ pub mod fix42 {
4545
include!(concat!(env!("OUT_DIR"), "/fix42.rs"));
4646
}
4747

48+
#[cfg(feature = "fix44")]
4849
#[allow(dead_code, unused, warnings, enum_variant_names)]
4950
#[rustfmt::skip]
5051
/// Field and message definitions for FIX.4.4.
5152
pub mod fix44 {
5253
include!(concat!(env!("OUT_DIR"), "/fix44.rs"));
5354
}
55+
56+
#[allow(dead_code, unused, warnings, enum_variant_names)]
57+
#[rustfmt::skip]
58+
/// Field and message definitions for FIX.4.4.
59+
pub mod fixt11 {
60+
include!(concat!(env!("OUT_DIR"), "/fixt11.rs"));
61+
}

crates/hotfix-message/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod field_map;
66
pub mod message;
77
pub mod parsed_message;
88
pub(crate) mod parts;
9+
pub mod session_fields;
910
mod tags;
1011

1112
pub use builder::{MessageBuilder, SOH};
@@ -14,6 +15,7 @@ pub use encoding::field_access::FieldType;
1415
pub use encoding::field_types;
1516
#[cfg(feature = "fix42")]
1617
pub use encoding::fix42;
18+
#[cfg(feature = "fix44")]
1719
pub use encoding::fix44;
1820
pub use encoding::{FieldValueError, HardCodedFixFieldDefinition};
1921
pub use hotfix_derive::FieldType;

crates/hotfix-message/src/message.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use std::io::Write;
22

33
use crate::FieldType;
4+
use crate::HardCodedFixFieldDefinition;
45
use crate::builder::SOH;
56
use crate::encoder::Encode;
67
use crate::error::EncodingResult;
78
use crate::field_map::{Field, FieldMap};
89
use crate::parts::{Body, Header, Part, RepeatingGroup, Trailer};
9-
use crate::{HardCodedFixFieldDefinition, fix44};
10+
use crate::session_fields::{BEGIN_STRING, BODY_LENGTH, CHECK_SUM, MSG_TYPE};
1011
use hotfix_dictionary::{FieldLocation, IsFieldDefinition};
1112

1213
pub struct Message {
@@ -22,8 +23,8 @@ impl Message {
2223
body: Body::default(),
2324
trailer: Trailer::default(),
2425
};
25-
msg.set(fix44::BEGIN_STRING, begin_string);
26-
msg.set(fix44::MSG_TYPE, message_type);
26+
msg.set(BEGIN_STRING, begin_string);
27+
msg.set(MSG_TYPE, message_type);
2728

2829
msg
2930
}
@@ -39,18 +40,14 @@ impl Message {
3940
pub fn encode(&mut self, config: &Config) -> EncodingResult<Vec<u8>> {
4041
let mut buffer = Vec::new();
4142

42-
self.trailer.pop(fix44::CHECK_SUM);
43+
self.trailer.pop(CHECK_SUM);
4344
let body_length = self.header.calculate_length()
4445
+ self.body.calculate_length()
4546
+ self.trailer.calculate_length();
46-
self.set(fix44::BODY_LENGTH, format!("{body_length}").as_str());
47+
self.set(BODY_LENGTH, format!("{body_length}").as_str());
4748
let check_sum_start = buffer.len();
4849

49-
let starting_fields = vec![
50-
fix44::BEGIN_STRING.tag(),
51-
fix44::BODY_LENGTH.tag(),
52-
fix44::MSG_TYPE.tag(),
53-
];
50+
let starting_fields = vec![BEGIN_STRING.tag(), BODY_LENGTH.tag(), MSG_TYPE.tag()];
5451
self.header
5552
.fields
5653
.write(config, &mut buffer, &starting_fields)?;
@@ -61,7 +58,7 @@ impl Message {
6158
.iter()
6259
.fold(0u8, |acc, &x| acc.wrapping_add(x));
6360
let checksum_value = format!("{checksum:03}");
64-
self.set(fix44::CHECK_SUM, checksum_value.as_str());
61+
self.set(CHECK_SUM, checksum_value.as_str());
6562
buffer.write_all(b"10=")?;
6663
buffer.write_all(checksum_value.as_bytes())?;
6764
buffer.push(config.separator);

0 commit comments

Comments
 (0)