rustyfix_dictionary/
builder.rs1use crate::{Dictionary, FixDatatype, FixmlComponentAttributes};
4use smallvec::SmallVec;
5use smartstring::alias::String as SmartString;
6
7pub struct DictionaryBuilder {
19 dict: Dictionary,
20}
21
22impl DictionaryBuilder {
24 pub fn new(dict: Dictionary) -> Self {
25 DictionaryBuilder { dict }
26 }
27
28 pub fn dict(&self) -> &Dictionary {
30 &self.dict
31 }
32
33 pub fn build(self) -> Dictionary {
35 self.dict
36 }
37
38 pub fn add_field(&mut self, field: FieldData) {
39 self.dict
40 .field_tags_by_name
41 .insert(field.name.clone(), field.tag);
42 self.dict.fields_by_tags.insert(field.tag, field);
43 }
44
45 pub fn add_message(&mut self, message: MessageData) {
46 self.dict
47 .message_msgtypes_by_name
48 .insert(message.name.clone(), message.msg_type.clone());
49 self.dict
50 .messages_by_msgtype
51 .insert(message.msg_type.clone(), message);
52 }
53
54 pub fn add_component(&mut self, component: ComponentData) {
55 self.dict
56 .components_by_name
57 .insert(component.name.clone(), component);
58 }
59
60 pub fn add_datatype(&mut self, datatype: DatatypeData) {
61 self.dict
62 .data_types_by_name
63 .insert(datatype.datatype.name().into(), datatype);
64 }
65
66 pub fn add_category(&mut self, category: CategoryData) {
67 self.dict
68 .categories_by_name
69 .insert(category.name.clone().into(), category);
70 }
71}
72
73#[derive(Clone, Debug)]
76pub struct FieldData {
77 pub name: SmartString,
79 pub tag: u32,
82 pub data_type_name: SmartString,
84 pub associated_data_tag: Option<usize>,
87 pub value_restrictions: Option<SmallVec<[FieldEnumData; 16]>>,
88 pub abbr_name: Option<String>,
92 pub base_category_id: Option<usize>,
94 pub base_category_abbr_name: Option<String>,
97 pub required: bool,
99 pub description: Option<String>,
100}
101
102#[derive(Clone, Debug)]
103pub struct CategoryData {
104 pub name: String,
106 pub fixml_filename: String,
108}
109
110#[derive(Clone, Debug, PartialEq)]
111pub struct DatatypeData {
112 pub datatype: FixDatatype,
114 pub description: String,
116 pub examples: SmallVec<[String; 4]>,
118 }
120
121#[derive(Clone, Debug)]
122pub struct AbbreviationData {
123 pub abbreviation: SmartString,
124 pub is_last: bool,
125}
126
127#[derive(Clone, Debug)]
128pub struct ComponentData {
129 pub id: usize,
132 pub component_type: FixmlComponentAttributes,
133 pub layout_items: Vec<LayoutItemData>,
134 pub category_name: SmartString,
135 pub name: SmartString,
137 pub abbr_name: Option<SmartString>,
139}
140
141#[derive(Clone, Debug)]
142#[allow(dead_code)]
143pub enum LayoutItemKindData {
144 Component {
145 name: SmartString,
146 },
147 Group {
148 len_field_tag: u32,
149 items: Vec<LayoutItemData>,
150 },
151 Field {
152 tag: u32,
153 },
154}
155
156#[derive(Clone, Debug)]
157pub struct LayoutItemData {
158 pub required: bool,
159 pub kind: LayoutItemKindData,
160}
161
162#[derive(Clone, Debug)]
163pub struct MessageData {
164 pub component_id: u32,
166 pub msg_type: SmartString,
169 pub name: SmartString,
171 pub category_name: SmartString,
173 pub section_id: String,
175 pub layout_items: Vec<LayoutItemData>,
176 pub abbr_name: Option<SmartString>,
178 pub required: bool,
181 pub description: String,
182 pub elaboration: Option<String>,
183}
184
185#[derive(Clone, Debug)]
186pub struct FieldEnumData {
187 pub value: String,
188 pub description: String,
189}