-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Generate message from FIX 4x XML spec
- Loading branch information
Showing
34 changed files
with
17,092 additions
and
9 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
[workspace] | ||
resolver = "2" | ||
members = ["quickfix-ffi", "quickfix-spec-parser", "quickfix"] | ||
members = [ | ||
"quickfix-ffi", | ||
"quickfix-msg-gen", | ||
"quickfix-spec-parser", | ||
"quickfix", | ||
"quickfix-msg40", | ||
"quickfix-msg41", | ||
"quickfix-msg42", | ||
"quickfix-msg43", | ||
"quickfix-msg44", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "quickfix-msg-gen" | ||
version = "0.1.0" | ||
authors = ["Arthur LE MOIGNE"] | ||
edition = "2021" | ||
description = "FIX code generator from XML spec file" | ||
repository = "https://github.com/arthurlm/quickfix-rs" | ||
license = "MIT" | ||
keywords = ["quickfix", "fix-protocol", "finance", "code-generator"] | ||
categories = ["development-tools::build-utils"] | ||
rust-version = "1.70.0" | ||
|
||
[dependencies] | ||
quickfix-spec-parser = { path = "../quickfix-spec-parser", version = "0.1.0" } | ||
quickfix = { path = "../quickfix", version = "0.1.0" } | ||
convert_case = "0.6.0" | ||
itertools = "0.12.0" | ||
bytes = "1.5.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std::collections::HashSet; | ||
|
||
use quickfix_spec_parser::{FieldValue, FixSpec, Message}; | ||
|
||
use crate::{FixCodeSpec, MessageField, MessageGroup, MessageSpec, SubComponent}; | ||
|
||
pub fn convert_spec(src: &FixSpec) -> FixCodeSpec { | ||
FixCodeSpec { | ||
field_specs: src.field_specs.clone(), | ||
headers: convert_field_value_list(src, &src.headers), | ||
trailers: convert_field_value_list(src, &src.trailers), | ||
messages: convert_messages(src, &src.messages), | ||
} | ||
} | ||
|
||
fn convert_field_value_list(spec: &FixSpec, values: &[FieldValue]) -> Vec<SubComponent> { | ||
let mut output = Vec::with_capacity(values.len()); | ||
|
||
// Convert recursively `FieldValue` to `SubComponent`. | ||
for value in values { | ||
match value { | ||
FieldValue::Field(x) => output.push(SubComponent::Field(MessageField { | ||
name: x.name.clone(), | ||
required: x.required, | ||
})), | ||
FieldValue::Group(x) => output.push(SubComponent::Group(MessageGroup { | ||
name: x.name.clone(), | ||
required: x.required, | ||
components: convert_field_value_list(spec, &x.values), | ||
})), | ||
FieldValue::Component(component) => { | ||
let component_spec = spec | ||
.component_specs | ||
.iter() | ||
.find(|x| x.name == component.name) | ||
.expect("Cannot find component"); | ||
|
||
output.extend(convert_field_value_list(spec, &component_spec.values)); | ||
} | ||
} | ||
} | ||
|
||
// Remove duplicate: example FIX4.3 -> RegistrationInstructions -> OwnershipType. | ||
let mut uniques = HashSet::new(); | ||
output.retain(|x| uniques.insert(x.name().to_string())); | ||
|
||
output | ||
} | ||
|
||
fn convert_messages(spec: &FixSpec, messages: &[Message]) -> Vec<MessageSpec> { | ||
messages | ||
.iter() | ||
.map(|message| MessageSpec { | ||
name: message.name.clone(), | ||
msg_type: message.msg_type.clone(), | ||
components: convert_field_value_list(spec, &message.values), | ||
}) | ||
.collect() | ||
} |
Oops, something went wrong.