@@ -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
1516var (
@@ -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
8793func 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}
0 commit comments