Skip to content

Commit 2e5a02e

Browse files
author
Chris Busbey
committed
generate setters
1 parent 012a57a commit 2e5a02e

File tree

1,108 files changed

+17366
-2
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,108 files changed

+17366
-2
lines changed

_gen/generate-components/main.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"bytes"
45
"flag"
56
"fmt"
67
"github.com/quickfixgo/quickfix/_gen"
@@ -158,7 +159,7 @@ func genComponentImports() (fileOut string) {
158159
}
159160

160161
fileOut += "import(\n"
161-
for i, _ := range imports {
162+
for i := range imports {
162163
fileOut += fmt.Sprintf("\"%v\"\n", i)
163164
}
164165
fileOut += ")\n"
@@ -225,6 +226,12 @@ func genHeader(header *datadictionary.MessageDef) {
225226
fileOut += genComponentImports()
226227
fileOut += delayOut
227228

229+
writer := new(bytes.Buffer)
230+
if err := gen.WriteFieldSetters(writer, "Header", header.FieldsInDeclarationOrder); err != nil {
231+
panic(err)
232+
}
233+
fileOut += writer.String()
234+
228235
gen.WriteFile(path.Join(pkg, "header.go"), fileOut)
229236
}
230237

@@ -238,6 +245,12 @@ func genTrailer(trailer *datadictionary.MessageDef) {
238245
}
239246
fileOut += "}\n"
240247

248+
writer := new(bytes.Buffer)
249+
if err := gen.WriteFieldSetters(writer, "Trailer", trailer.FieldsInDeclarationOrder); err != nil {
250+
panic(err)
251+
}
252+
fileOut += writer.String()
253+
241254
gen.WriteFile(path.Join(pkg, "trailer.go"), fileOut)
242255
}
243256

@@ -258,9 +271,20 @@ func genComponent(name string, component *datadictionary.Component) {
258271
fileOut += delayOut
259272
fileOut += "func New() *Component { return new(Component)}\n"
260273

274+
fileOut += genComponentSetters(component)
275+
261276
gen.WriteFile(path.Join(pkg, strings.ToLower(name), name+".go"), fileOut)
262277
}
263278

279+
func genComponentSetters(component *datadictionary.Component) string {
280+
writer := new(bytes.Buffer)
281+
if err := gen.WriteFieldSetters(writer, "Component", component.Fields); err != nil {
282+
panic(err)
283+
}
284+
285+
return writer.String()
286+
}
287+
264288
func main() {
265289
flag.Usage = usage
266290
flag.Parse()

_gen/generate-messages/main.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"bytes"
45
"flag"
56
"fmt"
67
"github.com/quickfixgo/quickfix/_gen"
@@ -47,7 +48,7 @@ import(
4748
`
4849
fileOut += fmt.Sprintf("\"github.com/quickfixgo/quickfix/%v\"\n", headerTrailerPkg())
4950

50-
for i, _ := range imports {
51+
for i := range imports {
5152
fileOut += fmt.Sprintf("\"%v\"\n", i)
5253
}
5354
fileOut += ")\n"
@@ -172,6 +173,13 @@ func genGroupDeclaration(field *datadictionary.FieldDef, parent string) (fileOut
172173

173174
fileOut += "}\n"
174175

176+
writer := new(bytes.Buffer)
177+
if err := gen.WriteFieldSetters(writer, field.Name, field.ChildFields); err != nil {
178+
panic(err)
179+
}
180+
fileOut += writer.String()
181+
fileOut += "\n"
182+
175183
return
176184
}
177185

@@ -231,6 +239,14 @@ func genMessage(msg *datadictionary.MessageDef, requiredFields []*datadictionary
231239
return fileOut
232240
}
233241

242+
func genMessageSetters(msg *datadictionary.MessageDef) string {
243+
writer := new(bytes.Buffer)
244+
if err := gen.WriteFieldSetters(writer, "Message", msg.FieldsInDeclarationOrder); err != nil {
245+
panic(err)
246+
}
247+
return writer.String()
248+
}
249+
234250
func genMessageRoute(msg *datadictionary.MessageDef) string {
235251
var beginStringEnum string
236252
if fixSpec.FIXType == "FIXT" {
@@ -284,6 +300,7 @@ func genMessagePkg(msg *datadictionary.MessageDef) {
284300

285301
fileOut += genMessageImports()
286302
fileOut += delayOut
303+
fileOut += genMessageSetters(msg)
287304
fileOut += genMessageRoute(msg)
288305

289306
gen.WriteFile(path.Join(pkg, strings.ToLower(msg.Name), msg.Name+".go"), fileOut)

_gen/helpers.go

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package gen
2+
3+
import (
4+
"fmt"
5+
"github.com/quickfixgo/quickfix/datadictionary"
6+
"io"
7+
"text/template"
8+
)
9+
10+
var fieldSetterTemplate *template.Template
11+
12+
func init() {
13+
tmplFuncs := make(template.FuncMap)
14+
tmplFuncs["fixFieldTypeToGoType"] = fixFieldTypeToGoType
15+
16+
fieldSetterTemplate = template.Must(template.New("Setters").Funcs(tmplFuncs).Parse(`
17+
func (m *{{.Receiver}}) Set{{.Name}}(v {{ if .IsGroup}}[]{{.Name}}{{else}}{{fixFieldTypeToGoType .Type}}{{end}}) {
18+
{{- if .IsGroup -}}m.{{.Name}} = v
19+
{{- else if .Required -}}m.{{.Name}} = v
20+
{{- else -}}m.{{.Name}} = &v
21+
{{- end}}}`))
22+
}
23+
24+
//WriteFieldSetters generates setters appropriate for Messages, Components and Repeating Groups
25+
func WriteFieldSetters(writer io.Writer, receiver string, fields []*datadictionary.FieldDef) error {
26+
type setter struct {
27+
Receiver string
28+
*datadictionary.FieldDef
29+
}
30+
31+
for _, field := range fields {
32+
if field.IsComponent() {
33+
continue
34+
}
35+
36+
if err := fieldSetterTemplate.Execute(writer, setter{receiver, field}); err != nil {
37+
return err
38+
}
39+
}
40+
41+
return nil
42+
}
43+
44+
func fixFieldTypeToGoType(fieldType string) string {
45+
switch fieldType {
46+
case "MULTIPLESTRINGVALUE", "MULTIPLEVALUESTRING":
47+
fallthrough
48+
case "MULTIPLECHARVALUE":
49+
fallthrough
50+
case "CHAR":
51+
fallthrough
52+
case "CURRENCY":
53+
fallthrough
54+
case "DATA":
55+
fallthrough
56+
case "MONTHYEAR":
57+
fallthrough
58+
case "LOCALMKTDATE":
59+
fallthrough
60+
case "DATE":
61+
fallthrough
62+
case "EXCHANGE":
63+
fallthrough
64+
case "LANGUAGE":
65+
fallthrough
66+
case "XMLDATA":
67+
fallthrough
68+
case "COUNTRY":
69+
fallthrough
70+
case "UTCTIMEONLY":
71+
fallthrough
72+
case "UTCDATE":
73+
fallthrough
74+
case "UTCDATEONLY":
75+
fallthrough
76+
case "TZTIMEONLY":
77+
fallthrough
78+
case "TZTIMESTAMP":
79+
fallthrough
80+
case "STRING":
81+
return "string"
82+
83+
case "BOOLEAN":
84+
return "bool"
85+
86+
case "LENGTH":
87+
fallthrough
88+
case "DAYOFMONTH":
89+
fallthrough
90+
case "NUMINGROUP":
91+
fallthrough
92+
case "SEQNUM":
93+
fallthrough
94+
case "INT":
95+
return "int"
96+
97+
case "TIME":
98+
fallthrough
99+
case "UTCTIMESTAMP":
100+
return "time.Time"
101+
102+
case "QTY":
103+
fallthrough
104+
case "QUANTITY":
105+
fallthrough
106+
case "AMT":
107+
fallthrough
108+
case "PRICE":
109+
fallthrough
110+
case "PRICEOFFSET":
111+
fallthrough
112+
case "PERCENTAGE":
113+
fallthrough
114+
case "FLOAT":
115+
return "float64"
116+
117+
default:
118+
panic(fmt.Sprintf("Unknown type '%v'\n", fieldType))
119+
}
120+
}

fix40/advertisement/Advertisement.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ type Message struct {
4848
//Marshal converts Message to a quickfix.Message instance
4949
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }
5050

51+
func (m *Message) SetAdvId(v int) { m.AdvId = v }
52+
func (m *Message) SetAdvTransType(v string) { m.AdvTransType = v }
53+
func (m *Message) SetAdvRefID(v int) { m.AdvRefID = &v }
54+
func (m *Message) SetSymbol(v string) { m.Symbol = v }
55+
func (m *Message) SetSymbolSfx(v string) { m.SymbolSfx = &v }
56+
func (m *Message) SetSecurityID(v string) { m.SecurityID = &v }
57+
func (m *Message) SetIDSource(v string) { m.IDSource = &v }
58+
func (m *Message) SetIssuer(v string) { m.Issuer = &v }
59+
func (m *Message) SetSecurityDesc(v string) { m.SecurityDesc = &v }
60+
func (m *Message) SetAdvSide(v string) { m.AdvSide = v }
61+
func (m *Message) SetShares(v int) { m.Shares = v }
62+
func (m *Message) SetPrice(v float64) { m.Price = &v }
63+
func (m *Message) SetCurrency(v string) { m.Currency = &v }
64+
func (m *Message) SetTransactTime(v time.Time) { m.TransactTime = &v }
65+
func (m *Message) SetText(v string) { m.Text = &v }
66+
5167
//A RouteOut is the callback type that should be implemented for routing Message
5268
type RouteOut func(msg Message, sessionID quickfix.SessionID) quickfix.MessageRejectError
5369

fix40/allocation/Allocation.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ type NoOrders struct {
2020
WaveNo *string `fix:"105"`
2121
}
2222

23+
func (m *NoOrders) SetClOrdID(v string) { m.ClOrdID = v }
24+
func (m *NoOrders) SetOrderID(v string) { m.OrderID = &v }
25+
func (m *NoOrders) SetListID(v string) { m.ListID = &v }
26+
func (m *NoOrders) SetWaveNo(v string) { m.WaveNo = &v }
27+
2328
//NoExecs is a repeating group in Allocation
2429
type NoExecs struct {
2530
//ExecID is a non-required field for NoExecs.
@@ -32,6 +37,11 @@ type NoExecs struct {
3237
LastMkt *string `fix:"30"`
3338
}
3439

40+
func (m *NoExecs) SetExecID(v int) { m.ExecID = &v }
41+
func (m *NoExecs) SetLastShares(v int) { m.LastShares = &v }
42+
func (m *NoExecs) SetLastPx(v float64) { m.LastPx = &v }
43+
func (m *NoExecs) SetLastMkt(v string) { m.LastMkt = &v }
44+
3545
//NoMiscFees is a repeating group in Allocation
3646
type NoMiscFees struct {
3747
//MiscFeeAmt is a non-required field for NoMiscFees.
@@ -42,6 +52,10 @@ type NoMiscFees struct {
4252
MiscFeeType *string `fix:"139"`
4353
}
4454

55+
func (m *NoMiscFees) SetMiscFeeAmt(v float64) { m.MiscFeeAmt = &v }
56+
func (m *NoMiscFees) SetMiscFeeCurr(v string) { m.MiscFeeCurr = &v }
57+
func (m *NoMiscFees) SetMiscFeeType(v string) { m.MiscFeeType = &v }
58+
4559
//NoAllocs is a repeating group in Allocation
4660
type NoAllocs struct {
4761
//AllocAccount is a required field for NoAllocs.
@@ -66,6 +80,17 @@ type NoAllocs struct {
6680
DlvyInst *string `fix:"86"`
6781
}
6882

83+
func (m *NoAllocs) SetAllocAccount(v string) { m.AllocAccount = v }
84+
func (m *NoAllocs) SetAllocShares(v int) { m.AllocShares = v }
85+
func (m *NoAllocs) SetProcessCode(v string) { m.ProcessCode = &v }
86+
func (m *NoAllocs) SetExecBroker(v string) { m.ExecBroker = &v }
87+
func (m *NoAllocs) SetClientID(v string) { m.ClientID = &v }
88+
func (m *NoAllocs) SetCommission(v float64) { m.Commission = &v }
89+
func (m *NoAllocs) SetCommType(v string) { m.CommType = &v }
90+
func (m *NoAllocs) SetNoDlvyInst(v int) { m.NoDlvyInst = &v }
91+
func (m *NoAllocs) SetBrokerOfCredit(v string) { m.BrokerOfCredit = &v }
92+
func (m *NoAllocs) SetDlvyInst(v string) { m.DlvyInst = &v }
93+
6994
//Message is a Allocation FIX Message
7095
type Message struct {
7196
FIXMsgType string `fix:"J"`
@@ -130,6 +155,34 @@ type Message struct {
130155
//Marshal converts Message to a quickfix.Message instance
131156
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }
132157

158+
func (m *Message) SetAllocID(v int) { m.AllocID = v }
159+
func (m *Message) SetAllocTransType(v string) { m.AllocTransType = v }
160+
func (m *Message) SetRefAllocID(v int) { m.RefAllocID = &v }
161+
func (m *Message) SetNoOrders(v []NoOrders) { m.NoOrders = v }
162+
func (m *Message) SetNoExecs(v []NoExecs) { m.NoExecs = v }
163+
func (m *Message) SetSide(v string) { m.Side = v }
164+
func (m *Message) SetSymbol(v string) { m.Symbol = v }
165+
func (m *Message) SetSymbolSfx(v string) { m.SymbolSfx = &v }
166+
func (m *Message) SetSecurityID(v string) { m.SecurityID = &v }
167+
func (m *Message) SetIDSource(v string) { m.IDSource = &v }
168+
func (m *Message) SetIssuer(v string) { m.Issuer = &v }
169+
func (m *Message) SetSecurityDesc(v string) { m.SecurityDesc = &v }
170+
func (m *Message) SetShares(v int) { m.Shares = v }
171+
func (m *Message) SetAvgPx(v float64) { m.AvgPx = v }
172+
func (m *Message) SetCurrency(v string) { m.Currency = &v }
173+
func (m *Message) SetAvgPrxPrecision(v int) { m.AvgPrxPrecision = &v }
174+
func (m *Message) SetTradeDate(v string) { m.TradeDate = v }
175+
func (m *Message) SetTransactTime(v time.Time) { m.TransactTime = &v }
176+
func (m *Message) SetSettlmntTyp(v string) { m.SettlmntTyp = &v }
177+
func (m *Message) SetFutSettDate(v string) { m.FutSettDate = &v }
178+
func (m *Message) SetNetMoney(v float64) { m.NetMoney = &v }
179+
func (m *Message) SetNoMiscFees(v []NoMiscFees) { m.NoMiscFees = v }
180+
func (m *Message) SetSettlCurrAmt(v float64) { m.SettlCurrAmt = &v }
181+
func (m *Message) SetSettlCurrency(v string) { m.SettlCurrency = &v }
182+
func (m *Message) SetOpenClose(v string) { m.OpenClose = &v }
183+
func (m *Message) SetText(v string) { m.Text = &v }
184+
func (m *Message) SetNoAllocs(v []NoAllocs) { m.NoAllocs = v }
185+
133186
//A RouteOut is the callback type that should be implemented for routing Message
134187
type RouteOut func(msg Message, sessionID quickfix.SessionID) quickfix.MessageRejectError
135188

fix40/allocationack/AllocationACK.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ type Message struct {
3434
//Marshal converts Message to a quickfix.Message instance
3535
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }
3636

37+
func (m *Message) SetClientID(v string) { m.ClientID = &v }
38+
func (m *Message) SetExecBroker(v string) { m.ExecBroker = &v }
39+
func (m *Message) SetAllocID(v int) { m.AllocID = v }
40+
func (m *Message) SetTradeDate(v string) { m.TradeDate = v }
41+
func (m *Message) SetTransactTime(v time.Time) { m.TransactTime = &v }
42+
func (m *Message) SetAllocStatus(v int) { m.AllocStatus = v }
43+
func (m *Message) SetAllocRejCode(v int) { m.AllocRejCode = &v }
44+
func (m *Message) SetText(v string) { m.Text = &v }
45+
3746
//A RouteOut is the callback type that should be implemented for routing Message
3847
type RouteOut func(msg Message, sessionID quickfix.SessionID) quickfix.MessageRejectError
3948

fix40/dontknowtrade/DontKnowTrade.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ type Message struct {
3535
//Marshal converts Message to a quickfix.Message instance
3636
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }
3737

38+
func (m *Message) SetOrderID(v string) { m.OrderID = &v }
39+
func (m *Message) SetExecID(v int) { m.ExecID = &v }
40+
func (m *Message) SetDKReason(v string) { m.DKReason = v }
41+
func (m *Message) SetSymbol(v string) { m.Symbol = v }
42+
func (m *Message) SetSide(v string) { m.Side = v }
43+
func (m *Message) SetOrderQty(v int) { m.OrderQty = v }
44+
func (m *Message) SetLastShares(v int) { m.LastShares = v }
45+
func (m *Message) SetLastPx(v float64) { m.LastPx = v }
46+
func (m *Message) SetText(v string) { m.Text = &v }
47+
3848
//A RouteOut is the callback type that should be implemented for routing Message
3949
type RouteOut func(msg Message, sessionID quickfix.SessionID) quickfix.MessageRejectError
4050

fix40/email/Email.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ type Message struct {
3636
//Marshal converts Message to a quickfix.Message instance
3737
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }
3838

39+
func (m *Message) SetEmailType(v string) { m.EmailType = v }
40+
func (m *Message) SetOrigTime(v time.Time) { m.OrigTime = &v }
41+
func (m *Message) SetRelatdSym(v string) { m.RelatdSym = &v }
42+
func (m *Message) SetOrderID(v string) { m.OrderID = &v }
43+
func (m *Message) SetClOrdID(v string) { m.ClOrdID = &v }
44+
func (m *Message) SetLinesOfText(v int) { m.LinesOfText = v }
45+
func (m *Message) SetText(v string) { m.Text = v }
46+
func (m *Message) SetRawDataLength(v int) { m.RawDataLength = &v }
47+
func (m *Message) SetRawData(v string) { m.RawData = &v }
48+
3949
//A RouteOut is the callback type that should be implemented for routing Message
4050
type RouteOut func(msg Message, sessionID quickfix.SessionID) quickfix.MessageRejectError
4151

0 commit comments

Comments
 (0)