Skip to content

Commit 4ac9ac6

Browse files
author
Chris Busbey
committed
renamed component names, dry refactoring
1 parent 2e5a02e commit 4ac9ac6

File tree

1,097 files changed

+7481
-8216
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,097 files changed

+7481
-8216
lines changed

_gen/generate-components/main.go

Lines changed: 21 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -37,121 +37,6 @@ func packageString() (s string) {
3737
return
3838
}
3939

40-
func writeField(field *datadictionary.FieldDef, componentName string) (s string) {
41-
if field.IsComponent() {
42-
imports[fmt.Sprintf("github.com/quickfixgo/quickfix/%v/%v", pkg, strings.ToLower(field.Component.Name))] = true
43-
44-
s += fmt.Sprintf("//%v Component\n", field.Component.Name)
45-
s += fmt.Sprintf("%v %v.Component\n", field.Component.Name, strings.ToLower(field.Component.Name))
46-
return
47-
}
48-
49-
if field.Required {
50-
s += fmt.Sprintf("//%v is a required field for %v.\n", field.Name, componentName)
51-
} else {
52-
s += fmt.Sprintf("//%v is a non-required field for %v.\n", field.Name, componentName)
53-
}
54-
55-
if field.IsGroup() {
56-
if field.Required {
57-
s += fmt.Sprintf("%v []%v `fix:\"%v\"`\n", field.Name, field.Name, field.Tag)
58-
} else {
59-
s += fmt.Sprintf("%v []%v `fix:\"%v,omitempty\"`\n", field.Name, field.Name, field.Tag)
60-
}
61-
return
62-
}
63-
64-
goType := ""
65-
switch field.Type {
66-
case "MULTIPLESTRINGVALUE", "MULTIPLEVALUESTRING":
67-
fallthrough
68-
case "MULTIPLECHARVALUE":
69-
fallthrough
70-
case "CHAR":
71-
fallthrough
72-
case "CURRENCY":
73-
fallthrough
74-
case "DATA":
75-
fallthrough
76-
case "MONTHYEAR":
77-
fallthrough
78-
case "LOCALMKTDATE":
79-
fallthrough
80-
case "EXCHANGE":
81-
fallthrough
82-
case "LANGUAGE":
83-
fallthrough
84-
case "XMLDATA":
85-
fallthrough
86-
case "COUNTRY":
87-
fallthrough
88-
case "UTCTIMEONLY":
89-
fallthrough
90-
case "UTCDATEONLY":
91-
fallthrough
92-
case "UTCDATE":
93-
fallthrough
94-
case "TZTIMEONLY":
95-
fallthrough
96-
case "TZTIMESTAMP":
97-
fallthrough
98-
case "STRING":
99-
goType = "string"
100-
101-
case "BOOLEAN":
102-
goType = "bool"
103-
104-
case "LENGTH":
105-
fallthrough
106-
case "DAYOFMONTH":
107-
fallthrough
108-
case "NUMINGROUP":
109-
fallthrough
110-
case "SEQNUM":
111-
fallthrough
112-
case "INT":
113-
goType = "int"
114-
115-
case "TIME":
116-
fallthrough
117-
case "UTCTIMESTAMP":
118-
imports["time"] = true
119-
goType = "time.Time"
120-
121-
case "QTY":
122-
fallthrough
123-
case "AMT":
124-
fallthrough
125-
case "PRICE":
126-
fallthrough
127-
case "PRICEOFFSET":
128-
fallthrough
129-
case "PERCENTAGE":
130-
fallthrough
131-
case "FLOAT":
132-
goType = "float64"
133-
134-
default:
135-
fmt.Printf("Unknown type '%v' for tag '%v'\n", field.Type, field.Tag)
136-
}
137-
138-
fixTags := strconv.Itoa(field.Tag)
139-
if field.Tag == 8 {
140-
if fixSpec.Major == 4 {
141-
fixTags = fmt.Sprintf("%v,default=FIX.%v.%v", fixTags, fixSpec.Major, fixSpec.Minor)
142-
} else {
143-
fixTags = fixTags + ",default=FIXT.1.1"
144-
}
145-
}
146-
147-
if field.Required {
148-
s += fmt.Sprintf("%v %v `fix:\"%v\"`\n", field.Name, goType, fixTags)
149-
} else {
150-
s += fmt.Sprintf("%v *%v `fix:\"%v\"`\n", field.Name, goType, fixTags)
151-
}
152-
return
153-
}
154-
15540
func genComponentImports() (fileOut string) {
15641

15742
if len(imports) == 0 {
@@ -185,11 +70,25 @@ func collectGroups(parent string, field *datadictionary.FieldDef, groups []group
18570
return groups
18671
}
18772

73+
func writeFieldDeclaration(field *datadictionary.FieldDef, componentName string) string {
74+
switch {
75+
case field.IsComponent():
76+
imports[fmt.Sprintf("github.com/quickfixgo/quickfix/%v/%v", pkg, strings.ToLower(field.Component.Name))] = true
77+
case !field.IsGroup():
78+
goType := gen.FixFieldTypeToGoType(field.Type)
79+
if goType == "time.Time" {
80+
imports["time"] = true
81+
}
82+
}
83+
84+
return gen.WriteFieldDeclaration(fixSpec.Major, fixSpec.Minor, field, componentName)
85+
}
86+
18887
func genGroupDeclaration(field *datadictionary.FieldDef, parent string) (fileOut string) {
18988
fileOut += fmt.Sprintf("//%v is a repeating group in %v\n", field.Name, parent)
19089
fileOut += fmt.Sprintf("type %v struct {\n", field.Name)
19190
for _, groupField := range field.ChildFields {
192-
fileOut += writeField(groupField, field.Name)
91+
fileOut += writeFieldDeclaration(groupField, field.Name)
19392
}
19493

19594
fileOut += "}\n"
@@ -218,7 +117,7 @@ func genHeader(header *datadictionary.MessageDef) {
218117
delayOut += fmt.Sprintf("//Header is the %v Header type\n", pkg)
219118
delayOut += "type Header struct {\n"
220119
for _, field := range header.FieldsInDeclarationOrder {
221-
delayOut += writeField(field, "Header")
120+
delayOut += writeFieldDeclaration(field, "Header")
222121
}
223122
delayOut += "}\n"
224123

@@ -241,7 +140,7 @@ func genTrailer(trailer *datadictionary.MessageDef) {
241140
fileOut += fmt.Sprintf("//Trailer is the %v Trailer type\n", pkg)
242141
fileOut += "type Trailer struct {\n"
243142
for _, field := range trailer.FieldsInDeclarationOrder {
244-
fileOut += writeField(field, "Trailer")
143+
fileOut += writeFieldDeclaration(field, "Trailer")
245144
}
246145
fileOut += "}\n"
247146

@@ -259,17 +158,16 @@ func genComponent(name string, component *datadictionary.Component) {
259158

260159
//delay output to determine imports
261160
delayOut := genGroupDeclarations(name, component.Fields)
262-
delayOut += fmt.Sprintf("//Component is a %v %v Component\n", pkg, name)
263-
delayOut += "type Component struct {\n"
161+
delayOut += fmt.Sprintf("//%v is a %v Component\n", name, pkg)
162+
delayOut += fmt.Sprintf("type %v struct {\n", name)
264163
for _, field := range component.Fields {
265-
delayOut += writeField(field, name)
164+
delayOut += writeFieldDeclaration(field, name)
266165
}
267166
delayOut += "}\n"
268167

269168
fileOut := fmt.Sprintf("package %v\n", strings.ToLower(name))
270169
fileOut += genComponentImports()
271170
fileOut += delayOut
272-
fileOut += "func New() *Component { return new(Component)}\n"
273171

274172
fileOut += genComponentSetters(component)
275173

@@ -278,7 +176,7 @@ func genComponent(name string, component *datadictionary.Component) {
278176

279177
func genComponentSetters(component *datadictionary.Component) string {
280178
writer := new(bytes.Buffer)
281-
if err := gen.WriteFieldSetters(writer, "Component", component.Fields); err != nil {
179+
if err := gen.WriteFieldSetters(writer, component.Name, component.Fields); err != nil {
282180
panic(err)
283181
}
284182

_gen/generate-messages/main.go

Lines changed: 12 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -55,120 +55,25 @@ import(
5555
return fileOut
5656
}
5757

58-
func genFieldDeclaration(field *datadictionary.FieldDef, parent string) (fileOut string) {
59-
if field.IsComponent() {
58+
func writeFieldDeclaration(field *datadictionary.FieldDef, componentName string) string {
59+
switch {
60+
case field.IsComponent():
6061
imports[fmt.Sprintf("github.com/quickfixgo/quickfix/%v/%v", pkg, strings.ToLower(field.Component.Name))] = true
61-
fileOut += fmt.Sprintf("//%v Component\n", field.Component.Name)
62-
fileOut += fmt.Sprintf("%v %v.Component\n", field.Component.Name, strings.ToLower(field.Component.Name))
63-
return
64-
}
65-
66-
if field.Required {
67-
fileOut += fmt.Sprintf("//%v is a required field for %v.\n", field.Name, parent)
68-
} else {
69-
fileOut += fmt.Sprintf("//%v is a non-required field for %v.\n", field.Name, parent)
70-
}
71-
if field.IsGroup() {
72-
if field.Required {
73-
fileOut += fmt.Sprintf("%v []%v `fix:\"%v\"`\n", field.Name, field.Name, field.Tag)
74-
} else {
75-
fileOut += fmt.Sprintf("%v []%v `fix:\"%v,omitempty\"`\n", field.Name, field.Name, field.Tag)
62+
case !field.IsGroup():
63+
goType := gen.FixFieldTypeToGoType(field.Type)
64+
if goType == "time.Time" {
65+
imports["time"] = true
7666
}
77-
return
7867
}
7968

80-
goType := ""
81-
switch field.Type {
82-
case "MULTIPLESTRINGVALUE", "MULTIPLEVALUESTRING":
83-
fallthrough
84-
case "MULTIPLECHARVALUE":
85-
fallthrough
86-
case "CHAR":
87-
fallthrough
88-
case "CURRENCY":
89-
fallthrough
90-
case "DATA":
91-
fallthrough
92-
case "MONTHYEAR":
93-
fallthrough
94-
case "LOCALMKTDATE":
95-
fallthrough
96-
case "DATE":
97-
fallthrough
98-
case "EXCHANGE":
99-
fallthrough
100-
case "LANGUAGE":
101-
fallthrough
102-
case "XMLDATA":
103-
fallthrough
104-
case "COUNTRY":
105-
fallthrough
106-
case "UTCTIMEONLY":
107-
fallthrough
108-
case "UTCDATE":
109-
fallthrough
110-
case "UTCDATEONLY":
111-
fallthrough
112-
case "TZTIMEONLY":
113-
fallthrough
114-
case "TZTIMESTAMP":
115-
fallthrough
116-
case "STRING":
117-
goType = "string"
118-
119-
case "BOOLEAN":
120-
goType = "bool"
121-
122-
case "LENGTH":
123-
fallthrough
124-
case "DAYOFMONTH":
125-
fallthrough
126-
case "NUMINGROUP":
127-
fallthrough
128-
case "SEQNUM":
129-
fallthrough
130-
case "INT":
131-
goType = "int"
132-
133-
case "TIME":
134-
fallthrough
135-
case "UTCTIMESTAMP":
136-
imports["time"] = true
137-
goType = "time.Time"
138-
139-
case "QTY":
140-
fallthrough
141-
case "QUANTITY":
142-
fallthrough
143-
case "AMT":
144-
fallthrough
145-
case "PRICE":
146-
fallthrough
147-
case "PRICEOFFSET":
148-
fallthrough
149-
case "PERCENTAGE":
150-
fallthrough
151-
case "FLOAT":
152-
goType = "float64"
153-
154-
default:
155-
fmt.Printf("Unknown type '%v' for tag '%v'\n", field.Type, field.Tag)
156-
}
157-
158-
if field.Required {
159-
fileOut += fmt.Sprintf("%v %v `fix:\"%v\"`\n", field.Name, goType, field.Tag)
160-
} else {
161-
fileOut += fmt.Sprintf("%v *%v `fix:\"%v\"`\n", field.Name, goType, field.Tag)
162-
}
163-
164-
return
69+
return gen.WriteFieldDeclaration(fixSpec.Major, fixSpec.Minor, field, componentName)
16570
}
16671

16772
func genGroupDeclaration(field *datadictionary.FieldDef, parent string) (fileOut string) {
16873
fileOut += fmt.Sprintf("//%v is a repeating group in %v\n", field.Name, parent)
16974
fileOut += fmt.Sprintf("type %v struct {\n", field.Name)
17075
for _, groupField := range field.ChildFields {
171-
fileOut += genFieldDeclaration(groupField, field.Name)
76+
fileOut += writeFieldDeclaration(groupField, field.Name)
17277
}
17378

17479
fileOut += "}\n"
@@ -227,11 +132,11 @@ func genMessage(msg *datadictionary.MessageDef, requiredFields []*datadictionary
227132
fileOut := fmt.Sprintf("//Message is a %v FIX Message\n", msg.Name)
228133
fileOut += "type Message struct {\n"
229134
fileOut += fmt.Sprintf("FIXMsgType string `fix:\"%v\"`\n", msg.MsgType)
230-
fileOut += fmt.Sprintf("Header %v.Header\n", headerTrailerPkg())
135+
fileOut += fmt.Sprintf("%v.Header\n", headerTrailerPkg())
231136
for _, field := range msg.FieldsInDeclarationOrder {
232-
fileOut += genFieldDeclaration(field, msg.Name)
137+
fileOut += writeFieldDeclaration(field, msg.Name)
233138
}
234-
fileOut += fmt.Sprintf("Trailer %v.Trailer\n", headerTrailerPkg())
139+
fileOut += fmt.Sprintf("%v.Trailer\n", headerTrailerPkg())
235140
fileOut += "}\n"
236141
fileOut += "//Marshal converts Message to a quickfix.Message instance\n"
237142
fileOut += "func (m Message) Marshal() quickfix.Message {return quickfix.Marshal(m)}\n"

0 commit comments

Comments
 (0)