Skip to content

Commit 6c16edb

Browse files
committed
Merge branch 'master' of github.com:quickfixgo/quickfix into filestore
2 parents 4795e2c + 36c0526 commit 6c16edb

File tree

638 files changed

+18049
-16169
lines changed

Some content is hidden

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

638 files changed

+18049
-16169
lines changed

_gen/generate-components/main.go

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import (
44
"bytes"
55
"flag"
66
"fmt"
7-
"github.com/quickfixgo/quickfix/_gen"
8-
"github.com/quickfixgo/quickfix/datadictionary"
97
"os"
108
"path"
119
"strconv"
1210
"strings"
11+
12+
"github.com/quickfixgo/quickfix/_gen"
13+
"github.com/quickfixgo/quickfix/datadictionary"
1314
)
1415

1516
var (
@@ -57,46 +58,51 @@ type group struct {
5758
field *datadictionary.FieldDef
5859
}
5960

60-
func collectGroups(parent string, field *datadictionary.FieldDef, groups []group) []group {
61-
if !field.IsGroup() {
62-
return groups
63-
}
61+
func collectGroups(parent string, part datadictionary.MessagePart, groups []group) []group {
62+
switch field := part.(type) {
63+
case *datadictionary.FieldDef:
64+
if !field.IsGroup() {
65+
return groups
66+
}
6467

65-
groups = append(groups, group{parent, field})
66-
for _, childField := range field.ChildFields {
67-
groups = collectGroups(field.Name, childField, groups)
68+
groups = append(groups, group{parent, field})
69+
for _, childField := range field.Parts {
70+
groups = collectGroups(field.Name(), childField, groups)
71+
}
6872
}
6973

7074
return groups
7175
}
7276

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
77+
func writeFieldDeclaration(part datadictionary.MessagePart, componentName string) string {
78+
switch field := part.(type) {
79+
case datadictionary.Component:
80+
imports[fmt.Sprintf("github.com/quickfixgo/quickfix/%v/%v", pkg, strings.ToLower(field.Name()))] = true
81+
case *datadictionary.FieldDef:
82+
if !field.IsGroup() {
83+
goType := gen.FixFieldTypeToGoType(field.Type)
84+
if goType == "time.Time" {
85+
imports["time"] = true
86+
}
8187
}
8288
}
8389

84-
return gen.WriteFieldDeclaration(fixSpec.Major, fixSpec.Minor, field, componentName)
90+
return gen.WriteFieldDeclaration(fixSpec.Major, fixSpec.Minor, part, componentName)
8591
}
8692

8793
func genGroupDeclaration(field *datadictionary.FieldDef, parent string) (fileOut string) {
88-
fileOut += fmt.Sprintf("//%v is a repeating group in %v\n", field.Name, parent)
89-
fileOut += fmt.Sprintf("type %v struct {\n", field.Name)
90-
for _, groupField := range field.ChildFields {
91-
fileOut += writeFieldDeclaration(groupField, field.Name)
94+
fileOut += fmt.Sprintf("//%v is a repeating group in %v\n", field.Name(), parent)
95+
fileOut += fmt.Sprintf("type %v struct {\n", field.Name())
96+
for _, groupField := range field.Parts {
97+
fileOut += writeFieldDeclaration(groupField, field.Name())
9298
}
9399

94100
fileOut += "}\n"
95101

96102
return
97103
}
98104

99-
func genGroupDeclarations(name string, fields []*datadictionary.FieldDef) (fileOut string) {
105+
func genGroupDeclarations(name string, fields []datadictionary.MessagePart) (fileOut string) {
100106
groups := []group{}
101107
for _, field := range fields {
102108
groups = collectGroups(name, field, groups)
@@ -113,10 +119,10 @@ func genHeader(header *datadictionary.MessageDef) {
113119
imports = make(map[string]bool)
114120

115121
//delay field output to determine imports
116-
delayOut := genGroupDeclarations("Header", header.FieldsInDeclarationOrder)
122+
delayOut := genGroupDeclarations("Header", header.Parts)
117123
delayOut += fmt.Sprintf("//Header is the %v Header type\n", pkg)
118124
delayOut += "type Header struct {\n"
119-
for _, field := range header.FieldsInDeclarationOrder {
125+
for _, field := range header.Parts {
120126
delayOut += writeFieldDeclaration(field, "Header")
121127
}
122128
delayOut += "}\n"
@@ -126,7 +132,7 @@ func genHeader(header *datadictionary.MessageDef) {
126132
fileOut += delayOut
127133

128134
writer := new(bytes.Buffer)
129-
if err := gen.WriteFieldSetters(writer, "Header", header.FieldsInDeclarationOrder); err != nil {
135+
if err := gen.WriteFieldSetters(writer, "Header", header.Parts); err != nil {
130136
panic(err)
131137
}
132138
fileOut += writer.String()
@@ -139,28 +145,28 @@ func genTrailer(trailer *datadictionary.MessageDef) {
139145
fileOut := packageString()
140146
fileOut += fmt.Sprintf("//Trailer is the %v Trailer type\n", pkg)
141147
fileOut += "type Trailer struct {\n"
142-
for _, field := range trailer.FieldsInDeclarationOrder {
148+
for _, field := range trailer.Parts {
143149
fileOut += writeFieldDeclaration(field, "Trailer")
144150
}
145151
fileOut += "}\n"
146152

147153
writer := new(bytes.Buffer)
148-
if err := gen.WriteFieldSetters(writer, "Trailer", trailer.FieldsInDeclarationOrder); err != nil {
154+
if err := gen.WriteFieldSetters(writer, "Trailer", trailer.Parts); err != nil {
149155
panic(err)
150156
}
151157
fileOut += writer.String()
152158

153159
gen.WriteFile(path.Join(pkg, "trailer.go"), fileOut)
154160
}
155161

156-
func genComponent(name string, component *datadictionary.Component) {
162+
func genComponent(name string, component *datadictionary.ComponentType) {
157163
imports = make(map[string]bool)
158164

159165
//delay output to determine imports
160-
delayOut := genGroupDeclarations(name, component.Fields)
166+
delayOut := genGroupDeclarations(name, component.Parts)
161167
delayOut += fmt.Sprintf("//%v is a %v Component\n", name, pkg)
162168
delayOut += fmt.Sprintf("type %v struct {\n", name)
163-
for _, field := range component.Fields {
169+
for _, field := range component.Parts {
164170
delayOut += writeFieldDeclaration(field, name)
165171
}
166172
delayOut += "}\n"
@@ -174,9 +180,9 @@ func genComponent(name string, component *datadictionary.Component) {
174180
gen.WriteFile(path.Join(pkg, strings.ToLower(name), name+".go"), fileOut)
175181
}
176182

177-
func genComponentSetters(component *datadictionary.Component) string {
183+
func genComponentSetters(component *datadictionary.ComponentType) string {
178184
writer := new(bytes.Buffer)
179-
if err := gen.WriteFieldSetters(writer, component.Name, component.Fields); err != nil {
185+
if err := gen.WriteFieldSetters(writer, component.Name(), component.Parts); err != nil {
180186
panic(err)
181187
}
182188

@@ -216,7 +222,7 @@ func main() {
216222
genTrailer(fixSpec.Trailer)
217223
}
218224

219-
for name, component := range fixSpec.Components {
225+
for name, component := range fixSpec.ComponentTypes {
220226
genComponent(name, component)
221227
}
222228
}

_gen/generate-fields/main.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package main
33
import (
44
"flag"
55
"fmt"
6-
"github.com/quickfixgo/quickfix/_gen"
7-
"github.com/quickfixgo/quickfix/datadictionary"
86
"os"
97
"sort"
8+
9+
"github.com/quickfixgo/quickfix/_gen"
10+
"github.com/quickfixgo/quickfix/datadictionary"
1011
)
1112

1213
var (
@@ -138,16 +139,16 @@ func genFields() {
138139
fmt.Printf("Unknown type '%v' for tag '%v'\n", field.Type, tag)
139140
}
140141

141-
fileOut += fmt.Sprintf("//%vField is a %v field\n", field.Name, field.Type)
142-
fileOut += fmt.Sprintf("type %vField struct { quickfix.%v }\n", field.Name, baseType)
143-
fileOut += fmt.Sprintf("//Tag returns tag.%v (%v)\n", field.Name, field.Tag)
144-
fileOut += fmt.Sprintf("func (f %vField) Tag() quickfix.Tag {return tag.%v}\n", field.Name, field.Name)
142+
fileOut += fmt.Sprintf("//%vField is a %v field\n", field.Name(), field.Type)
143+
fileOut += fmt.Sprintf("type %vField struct { quickfix.%v }\n", field.Name(), baseType)
144+
fileOut += fmt.Sprintf("//Tag returns tag.%v (%v)\n", field.Name(), field.Tag)
145+
fileOut += fmt.Sprintf("func (f %vField) Tag() quickfix.Tag {return tag.%v}\n", field.Name(), field.Name())
145146

146147
switch goType {
147148
case "bool", "int", "float64", "string":
148-
fileOut += fmt.Sprintf("//New%v returns a new %vField initialized with val\n", field.Name, field.Name)
149-
fileOut += fmt.Sprintf("func New%v(val %v) *%vField {\n", field.Name, goType, field.Name)
150-
fileOut += fmt.Sprintf("return &%vField{quickfix.%v(val)}\n", field.Name, baseType)
149+
fileOut += fmt.Sprintf("//New%v returns a new %vField initialized with val\n", field.Name(), field.Name())
150+
fileOut += fmt.Sprintf("func New%v(val %v) *%vField {\n", field.Name(), goType, field.Name())
151+
fileOut += fmt.Sprintf("return &%vField{quickfix.%v(val)}\n", field.Name(), baseType)
151152
fileOut += "}\n"
152153
}
153154
}
@@ -188,9 +189,9 @@ func main() {
188189
}
189190

190191
for _, field := range spec.FieldTypeByTag {
191-
fieldMap[field.Name] = int(field.Tag)
192+
fieldMap[field.Name()] = int(field.Tag)
192193

193-
if oldField, ok := fieldTypeMap[field.Name]; ok {
194+
if oldField, ok := fieldTypeMap[field.Name()]; ok {
194195
//merge old enums with new
195196
if len(oldField.Enums) > 0 && field.Enums == nil {
196197
field.Enums = make(map[string]datadictionary.Enum)
@@ -214,7 +215,7 @@ func main() {
214215
}
215216
}
216217

217-
fieldTypeMap[field.Name] = field
218+
fieldTypeMap[field.Name()] = field
218219
}
219220
}
220221

_gen/generate-messages/main.go

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import (
44
"bytes"
55
"flag"
66
"fmt"
7-
"github.com/quickfixgo/quickfix/_gen"
8-
"github.com/quickfixgo/quickfix/datadictionary"
97
"os"
108
"path"
119
"sort"
1210
"strconv"
1311
"strings"
12+
13+
"github.com/quickfixgo/quickfix/_gen"
14+
"github.com/quickfixgo/quickfix/datadictionary"
1415
)
1516

1617
var (
@@ -55,31 +56,33 @@ import(
5556
return fileOut
5657
}
5758

58-
func writeFieldDeclaration(field *datadictionary.FieldDef, componentName string) string {
59-
switch {
60-
case field.IsComponent():
61-
imports[fmt.Sprintf("github.com/quickfixgo/quickfix/%v/%v", pkg, strings.ToLower(field.Component.Name))] = true
62-
case !field.IsGroup():
63-
goType := gen.FixFieldTypeToGoType(field.Type)
64-
if goType == "time.Time" {
65-
imports["time"] = true
59+
func writeFieldDeclaration(part datadictionary.MessagePart, componentName string) string {
60+
switch field := part.(type) {
61+
case datadictionary.Component:
62+
imports[fmt.Sprintf("github.com/quickfixgo/quickfix/%v/%v", pkg, strings.ToLower(field.Name()))] = true
63+
case *datadictionary.FieldDef:
64+
if !field.IsGroup() {
65+
goType := gen.FixFieldTypeToGoType(field.Type)
66+
if goType == "time.Time" {
67+
imports["time"] = true
68+
}
6669
}
6770
}
6871

69-
return gen.WriteFieldDeclaration(fixSpec.Major, fixSpec.Minor, field, componentName)
72+
return gen.WriteFieldDeclaration(fixSpec.Major, fixSpec.Minor, part, componentName)
7073
}
7174

7275
func genGroupDeclaration(field *datadictionary.FieldDef, parent string) (fileOut string) {
73-
fileOut += fmt.Sprintf("//%v is a repeating group in %v\n", field.Name, parent)
74-
fileOut += fmt.Sprintf("type %v struct {\n", field.Name)
75-
for _, groupField := range field.ChildFields {
76-
fileOut += writeFieldDeclaration(groupField, field.Name)
76+
fileOut += fmt.Sprintf("//%v is a repeating group in %v\n", field.Name(), parent)
77+
fileOut += fmt.Sprintf("type %v struct {\n", field.Name())
78+
for _, groupField := range field.Parts {
79+
fileOut += writeFieldDeclaration(groupField, field.Name())
7780
}
7881

7982
fileOut += "}\n"
8083

8184
writer := new(bytes.Buffer)
82-
if err := gen.WriteFieldSetters(writer, field.Name, field.ChildFields); err != nil {
85+
if err := gen.WriteFieldSetters(writer, field.Name(), field.Parts); err != nil {
8386
panic(err)
8487
}
8588
fileOut += writer.String()
@@ -93,22 +96,25 @@ type group struct {
9396
field *datadictionary.FieldDef
9497
}
9598

96-
func collectGroups(parent string, field *datadictionary.FieldDef, groups []group) []group {
97-
if !field.IsGroup() {
98-
return groups
99-
}
99+
func collectGroups(parent string, part datadictionary.MessagePart, groups []group) []group {
100+
switch field := part.(type) {
101+
case *datadictionary.FieldDef:
102+
if !field.IsGroup() {
103+
return groups
104+
}
100105

101-
groups = append(groups, group{parent, field})
102-
for _, childField := range field.ChildFields {
103-
groups = collectGroups(field.Name, childField, groups)
106+
groups = append(groups, group{parent, field})
107+
for _, childField := range field.Parts {
108+
groups = collectGroups(field.Name(), childField, groups)
109+
}
104110
}
105111

106112
return groups
107113
}
108114

109115
func genGroupDeclarations(msg *datadictionary.MessageDef) (fileOut string) {
110116
groups := []group{}
111-
for _, field := range msg.FieldsInDeclarationOrder {
117+
for _, field := range msg.Parts {
112118
groups = collectGroups(msg.Name, field, groups)
113119
}
114120

@@ -128,12 +134,12 @@ func headerTrailerPkg() string {
128134
return pkg
129135
}
130136

131-
func genMessage(msg *datadictionary.MessageDef, requiredFields []*datadictionary.FieldDef) string {
137+
func genMessage(msg *datadictionary.MessageDef) string {
132138
fileOut := fmt.Sprintf("//Message is a %v FIX Message\n", msg.Name)
133139
fileOut += "type Message struct {\n"
134140
fileOut += fmt.Sprintf("FIXMsgType string `fix:\"%v\"`\n", msg.MsgType)
135141
fileOut += fmt.Sprintf("%v.Header\n", headerTrailerPkg())
136-
for _, field := range msg.FieldsInDeclarationOrder {
142+
for _, field := range msg.Parts {
137143
fileOut += writeFieldDeclaration(field, msg.Name)
138144
}
139145
fileOut += fmt.Sprintf("%v.Trailer\n", headerTrailerPkg())
@@ -146,7 +152,7 @@ func genMessage(msg *datadictionary.MessageDef, requiredFields []*datadictionary
146152

147153
func genMessageSetters(msg *datadictionary.MessageDef) string {
148154
writer := new(bytes.Buffer)
149-
if err := gen.WriteFieldSetters(writer, "Message", msg.FieldsInDeclarationOrder); err != nil {
155+
if err := gen.WriteFieldSetters(writer, "Message", msg.Parts); err != nil {
150156
panic(err)
151157
}
152158
return writer.String()
@@ -185,13 +191,6 @@ func Route(router RouteOut) (string,string,quickfix.MessageRoute) {
185191
}
186192

187193
func genMessagePkg(msg *datadictionary.MessageDef) {
188-
requiredFields := make([]*datadictionary.FieldDef, 0, len(msg.FieldsInDeclarationOrder))
189-
for _, field := range msg.FieldsInDeclarationOrder {
190-
if field.Required {
191-
requiredFields = append(requiredFields, field)
192-
}
193-
}
194-
195194
pkgName := strings.ToLower(msg.Name)
196195
imports = make(map[string]bool)
197196

@@ -201,7 +200,7 @@ func genMessagePkg(msg *datadictionary.MessageDef) {
201200
//run through group and message declarations to collect required imports first
202201
delayOut := ""
203202
delayOut += genGroupDeclarations(msg)
204-
delayOut += genMessage(msg, requiredFields)
203+
delayOut += genMessage(msg)
205204

206205
fileOut += genMessageImports()
207206
fileOut += delayOut

0 commit comments

Comments
 (0)