Skip to content

Commit 36c0526

Browse files
committed
Merge pull request #79 from cbusbey/optionalComps
support for optional components, component setters
2 parents e979c5a + ea86768 commit 36c0526

File tree

631 files changed

+17708
-14350
lines changed

Some content is hidden

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

631 files changed

+17708
-14350
lines changed

_gen/helpers.go

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,24 @@ import (
1313
var fieldSetterTemplate *template.Template
1414

1515
func init() {
16-
tmplFuncs := make(template.FuncMap)
17-
tmplFuncs["fixFieldTypeToGoType"] = FixFieldTypeToGoType
16+
tmplFuncs := template.FuncMap{
17+
"fixFieldTypeToGoType": FixFieldTypeToGoType,
18+
"toLower": strings.ToLower,
19+
}
1820

1921
fieldSetterTemplate = template.Must(template.New("Setters").Funcs(tmplFuncs).Parse(`
22+
{{define "fieldSetter"}}
2023
func (m *{{.Receiver}}) Set{{.Name}}(v {{ if .IsGroup}}[]{{.Name}}{{else}}{{fixFieldTypeToGoType .Type}}{{end}}) {
2124
{{- if .IsGroup -}}m.{{.Name}} = v
2225
{{- else if .Required -}}m.{{.Name}} = v
2326
{{- else -}}m.{{.Name}} = &v
24-
{{- end}}}`))
27+
{{- end}}}{{end}}
28+
29+
{{define "compSetter"}}
30+
func (m *{{.Receiver}}) Set{{.Name}}(v {{toLower .Name}}.{{ .Name}}) {
31+
{{- if .Required -}}m.{{.Name}} = v
32+
{{- else -}}m.{{.Name}} = &v
33+
{{- end}}}{{end}}`))
2534
}
2635

2736
//WriteFieldSetters generates setters appropriate for Messages, Components or Repeating Groups
@@ -31,10 +40,19 @@ func WriteFieldSetters(writer io.Writer, receiver string, parts []datadictionary
3140
*datadictionary.FieldDef
3241
}
3342

43+
type componentSetter struct {
44+
Receiver string
45+
datadictionary.Component
46+
}
47+
3448
for _, part := range parts {
3549
switch field := part.(type) {
50+
case datadictionary.Component:
51+
if err := fieldSetterTemplate.ExecuteTemplate(writer, "compSetter", componentSetter{receiver, field}); err != nil {
52+
return err
53+
}
3654
case *datadictionary.FieldDef:
37-
if err := fieldSetterTemplate.Execute(writer, setter{receiver, field}); err != nil {
55+
if err := fieldSetterTemplate.ExecuteTemplate(writer, "fieldSetter", setter{receiver, field}); err != nil {
3856
return err
3957
}
4058
}
@@ -46,8 +64,13 @@ func WriteFieldSetters(writer io.Writer, receiver string, parts []datadictionary
4664
func WriteFieldDeclaration(fixSpecMajor int, fixSpecMinor int, part datadictionary.MessagePart, componentName string) (s string) {
4765
switch field := part.(type) {
4866
case datadictionary.Component:
49-
s += fmt.Sprintf("//%v Component\n", field.Name())
50-
s += fmt.Sprintf("%v.%v\n", strings.ToLower(field.Name()), field.Name())
67+
if field.Required() {
68+
s += fmt.Sprintf("//%v is a required component for %v.\n", field.Name(), componentName)
69+
s += fmt.Sprintf("%v.%v\n", strings.ToLower(field.Name()), field.Name())
70+
} else {
71+
s += fmt.Sprintf("//%v is a non-required component for %v.\n", field.Name(), componentName)
72+
s += fmt.Sprintf("%v *%v.%v\n", field.Name(), strings.ToLower(field.Name()), field.Name())
73+
}
5174
return
5275

5376
case *datadictionary.FieldDef:

datadictionary/build.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,20 +181,18 @@ func (b builder) buildGroupFieldDef(xmlField *XMLComponentMember, groupFieldType
181181
for _, member := range xmlField.Members {
182182
if member.XMLName.Local == "component" {
183183
var err error
184-
var comp *ComponentType
185-
if comp, err = b.findOrBuildComponentType(member); err != nil {
184+
var compType *ComponentType
185+
if compType, err = b.findOrBuildComponentType(member); err != nil {
186186
return nil, err
187187
}
188188

189-
parts = append(parts, Component{ComponentType: comp, required: (member.Required == "Y")})
190-
//FIXME: set fields
191-
for _, f := range comp.Parts {
192-
switch field := f.(type) {
193-
case *FieldDef:
194-
fields = append(fields, field)
195-
}
189+
comp := Component{
190+
ComponentType: compType,
191+
required: (member.Required == "Y"),
196192
}
197193

194+
parts = append(parts, comp)
195+
fields = append(fields, comp.Fields...)
198196
} else {
199197
var f *FieldDef
200198
var err error

fix43/advertisement/Advertisement.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type Message struct {
1919
AdvTransType string `fix:"5"`
2020
//AdvRefID is a non-required field for Advertisement.
2121
AdvRefID *string `fix:"3"`
22-
//Instrument Component
22+
//Instrument is a required component for Advertisement.
2323
instrument.Instrument
2424
//AdvSide is a required field for Advertisement.
2525
AdvSide string `fix:"4"`
@@ -53,22 +53,23 @@ type Message struct {
5353
//Marshal converts Message to a quickfix.Message instance
5454
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }
5555

56-
func (m *Message) SetAdvId(v string) { m.AdvId = v }
57-
func (m *Message) SetAdvTransType(v string) { m.AdvTransType = v }
58-
func (m *Message) SetAdvRefID(v string) { m.AdvRefID = &v }
59-
func (m *Message) SetAdvSide(v string) { m.AdvSide = v }
60-
func (m *Message) SetQuantity(v float64) { m.Quantity = v }
61-
func (m *Message) SetPrice(v float64) { m.Price = &v }
62-
func (m *Message) SetCurrency(v string) { m.Currency = &v }
63-
func (m *Message) SetTradeDate(v string) { m.TradeDate = &v }
64-
func (m *Message) SetTransactTime(v time.Time) { m.TransactTime = &v }
65-
func (m *Message) SetText(v string) { m.Text = &v }
66-
func (m *Message) SetEncodedTextLen(v int) { m.EncodedTextLen = &v }
67-
func (m *Message) SetEncodedText(v string) { m.EncodedText = &v }
68-
func (m *Message) SetURLLink(v string) { m.URLLink = &v }
69-
func (m *Message) SetLastMkt(v string) { m.LastMkt = &v }
70-
func (m *Message) SetTradingSessionID(v string) { m.TradingSessionID = &v }
71-
func (m *Message) SetTradingSessionSubID(v string) { m.TradingSessionSubID = &v }
56+
func (m *Message) SetAdvId(v string) { m.AdvId = v }
57+
func (m *Message) SetAdvTransType(v string) { m.AdvTransType = v }
58+
func (m *Message) SetAdvRefID(v string) { m.AdvRefID = &v }
59+
func (m *Message) SetInstrument(v instrument.Instrument) { m.Instrument = v }
60+
func (m *Message) SetAdvSide(v string) { m.AdvSide = v }
61+
func (m *Message) SetQuantity(v float64) { m.Quantity = 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) SetTradeDate(v string) { m.TradeDate = &v }
65+
func (m *Message) SetTransactTime(v time.Time) { m.TransactTime = &v }
66+
func (m *Message) SetText(v string) { m.Text = &v }
67+
func (m *Message) SetEncodedTextLen(v int) { m.EncodedTextLen = &v }
68+
func (m *Message) SetEncodedText(v string) { m.EncodedText = &v }
69+
func (m *Message) SetURLLink(v string) { m.URLLink = &v }
70+
func (m *Message) SetLastMkt(v string) { m.LastMkt = &v }
71+
func (m *Message) SetTradingSessionID(v string) { m.TradingSessionID = &v }
72+
func (m *Message) SetTradingSessionSubID(v string) { m.TradingSessionSubID = &v }
7273

7374
//A RouteOut is the callback type that should be implemented for routing Message
7475
type RouteOut func(msg Message, sessionID quickfix.SessionID) quickfix.MessageRejectError

fix43/allocation/Allocation.go

Lines changed: 66 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ type NoAllocs struct {
6464
IndividualAllocID *string `fix:"467"`
6565
//ProcessCode is a non-required field for NoAllocs.
6666
ProcessCode *string `fix:"81"`
67-
//NestedParties Component
68-
nestedparties.NestedParties
67+
//NestedParties is a non-required component for NoAllocs.
68+
NestedParties *nestedparties.NestedParties
6969
//NotifyBrokerOfCredit is a non-required field for NoAllocs.
7070
NotifyBrokerOfCredit *bool `fix:"208"`
7171
//AllocHandlInst is a non-required field for NoAllocs.
@@ -76,8 +76,8 @@ type NoAllocs struct {
7676
EncodedAllocTextLen *int `fix:"360"`
7777
//EncodedAllocText is a non-required field for NoAllocs.
7878
EncodedAllocText *string `fix:"361"`
79-
//CommissionData Component
80-
commissiondata.CommissionData
79+
//CommissionData is a non-required component for NoAllocs.
80+
CommissionData *commissiondata.CommissionData
8181
//AllocAvgPx is a non-required field for NoAllocs.
8282
AllocAvgPx *float64 `fix:"153"`
8383
//AllocNetMoney is a non-required field for NoAllocs.
@@ -98,25 +98,27 @@ type NoAllocs struct {
9898
NoMiscFees []NoMiscFees `fix:"136,omitempty"`
9999
}
100100

101-
func (m *NoAllocs) SetAllocAccount(v string) { m.AllocAccount = &v }
102-
func (m *NoAllocs) SetAllocPrice(v float64) { m.AllocPrice = &v }
103-
func (m *NoAllocs) SetAllocQty(v float64) { m.AllocQty = &v }
104-
func (m *NoAllocs) SetIndividualAllocID(v string) { m.IndividualAllocID = &v }
105-
func (m *NoAllocs) SetProcessCode(v string) { m.ProcessCode = &v }
106-
func (m *NoAllocs) SetNotifyBrokerOfCredit(v bool) { m.NotifyBrokerOfCredit = &v }
107-
func (m *NoAllocs) SetAllocHandlInst(v int) { m.AllocHandlInst = &v }
108-
func (m *NoAllocs) SetAllocText(v string) { m.AllocText = &v }
109-
func (m *NoAllocs) SetEncodedAllocTextLen(v int) { m.EncodedAllocTextLen = &v }
110-
func (m *NoAllocs) SetEncodedAllocText(v string) { m.EncodedAllocText = &v }
111-
func (m *NoAllocs) SetAllocAvgPx(v float64) { m.AllocAvgPx = &v }
112-
func (m *NoAllocs) SetAllocNetMoney(v float64) { m.AllocNetMoney = &v }
113-
func (m *NoAllocs) SetSettlCurrAmt(v float64) { m.SettlCurrAmt = &v }
114-
func (m *NoAllocs) SetSettlCurrency(v string) { m.SettlCurrency = &v }
115-
func (m *NoAllocs) SetSettlCurrFxRate(v float64) { m.SettlCurrFxRate = &v }
116-
func (m *NoAllocs) SetSettlCurrFxRateCalc(v string) { m.SettlCurrFxRateCalc = &v }
117-
func (m *NoAllocs) SetAccruedInterestAmt(v float64) { m.AccruedInterestAmt = &v }
118-
func (m *NoAllocs) SetSettlInstMode(v string) { m.SettlInstMode = &v }
119-
func (m *NoAllocs) SetNoMiscFees(v []NoMiscFees) { m.NoMiscFees = v }
101+
func (m *NoAllocs) SetAllocAccount(v string) { m.AllocAccount = &v }
102+
func (m *NoAllocs) SetAllocPrice(v float64) { m.AllocPrice = &v }
103+
func (m *NoAllocs) SetAllocQty(v float64) { m.AllocQty = &v }
104+
func (m *NoAllocs) SetIndividualAllocID(v string) { m.IndividualAllocID = &v }
105+
func (m *NoAllocs) SetProcessCode(v string) { m.ProcessCode = &v }
106+
func (m *NoAllocs) SetNestedParties(v nestedparties.NestedParties) { m.NestedParties = &v }
107+
func (m *NoAllocs) SetNotifyBrokerOfCredit(v bool) { m.NotifyBrokerOfCredit = &v }
108+
func (m *NoAllocs) SetAllocHandlInst(v int) { m.AllocHandlInst = &v }
109+
func (m *NoAllocs) SetAllocText(v string) { m.AllocText = &v }
110+
func (m *NoAllocs) SetEncodedAllocTextLen(v int) { m.EncodedAllocTextLen = &v }
111+
func (m *NoAllocs) SetEncodedAllocText(v string) { m.EncodedAllocText = &v }
112+
func (m *NoAllocs) SetCommissionData(v commissiondata.CommissionData) { m.CommissionData = &v }
113+
func (m *NoAllocs) SetAllocAvgPx(v float64) { m.AllocAvgPx = &v }
114+
func (m *NoAllocs) SetAllocNetMoney(v float64) { m.AllocNetMoney = &v }
115+
func (m *NoAllocs) SetSettlCurrAmt(v float64) { m.SettlCurrAmt = &v }
116+
func (m *NoAllocs) SetSettlCurrency(v string) { m.SettlCurrency = &v }
117+
func (m *NoAllocs) SetSettlCurrFxRate(v float64) { m.SettlCurrFxRate = &v }
118+
func (m *NoAllocs) SetSettlCurrFxRateCalc(v string) { m.SettlCurrFxRateCalc = &v }
119+
func (m *NoAllocs) SetAccruedInterestAmt(v float64) { m.AccruedInterestAmt = &v }
120+
func (m *NoAllocs) SetSettlInstMode(v string) { m.SettlInstMode = &v }
121+
func (m *NoAllocs) SetNoMiscFees(v []NoMiscFees) { m.NoMiscFees = v }
120122

121123
//NoMiscFees is a repeating group in NoAllocs
122124
type NoMiscFees struct {
@@ -156,7 +158,7 @@ type Message struct {
156158
NoExecs []NoExecs `fix:"124,omitempty"`
157159
//Side is a required field for Allocation.
158160
Side string `fix:"54"`
159-
//Instrument Component
161+
//Instrument is a required component for Allocation.
160162
instrument.Instrument
161163
//Quantity is a required field for Allocation.
162164
Quantity float64 `fix:"53"`
@@ -176,8 +178,8 @@ type Message struct {
176178
Currency *string `fix:"15"`
177179
//AvgPrxPrecision is a non-required field for Allocation.
178180
AvgPrxPrecision *int `fix:"74"`
179-
//Parties Component
180-
parties.Parties
181+
//Parties is a non-required component for Allocation.
182+
Parties *parties.Parties
181183
//TradeDate is a required field for Allocation.
182184
TradeDate string `fix:"75"`
183185
//TransactTime is a non-required field for Allocation.
@@ -218,42 +220,44 @@ type Message struct {
218220
//Marshal converts Message to a quickfix.Message instance
219221
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }
220222

221-
func (m *Message) SetAllocID(v string) { m.AllocID = v }
222-
func (m *Message) SetAllocTransType(v string) { m.AllocTransType = v }
223-
func (m *Message) SetAllocType(v int) { m.AllocType = v }
224-
func (m *Message) SetRefAllocID(v string) { m.RefAllocID = &v }
225-
func (m *Message) SetAllocLinkID(v string) { m.AllocLinkID = &v }
226-
func (m *Message) SetAllocLinkType(v int) { m.AllocLinkType = &v }
227-
func (m *Message) SetBookingRefID(v string) { m.BookingRefID = &v }
228-
func (m *Message) SetNoOrders(v []NoOrders) { m.NoOrders = v }
229-
func (m *Message) SetNoExecs(v []NoExecs) { m.NoExecs = v }
230-
func (m *Message) SetSide(v string) { m.Side = v }
231-
func (m *Message) SetQuantity(v float64) { m.Quantity = v }
232-
func (m *Message) SetLastMkt(v string) { m.LastMkt = &v }
233-
func (m *Message) SetTradeOriginationDate(v string) { m.TradeOriginationDate = &v }
234-
func (m *Message) SetTradingSessionID(v string) { m.TradingSessionID = &v }
235-
func (m *Message) SetTradingSessionSubID(v string) { m.TradingSessionSubID = &v }
236-
func (m *Message) SetPriceType(v int) { m.PriceType = &v }
237-
func (m *Message) SetAvgPx(v float64) { m.AvgPx = v }
238-
func (m *Message) SetCurrency(v string) { m.Currency = &v }
239-
func (m *Message) SetAvgPrxPrecision(v int) { m.AvgPrxPrecision = &v }
240-
func (m *Message) SetTradeDate(v string) { m.TradeDate = v }
241-
func (m *Message) SetTransactTime(v time.Time) { m.TransactTime = &v }
242-
func (m *Message) SetSettlmntTyp(v string) { m.SettlmntTyp = &v }
243-
func (m *Message) SetFutSettDate(v string) { m.FutSettDate = &v }
244-
func (m *Message) SetGrossTradeAmt(v float64) { m.GrossTradeAmt = &v }
245-
func (m *Message) SetConcession(v float64) { m.Concession = &v }
246-
func (m *Message) SetTotalTakedown(v float64) { m.TotalTakedown = &v }
247-
func (m *Message) SetNetMoney(v float64) { m.NetMoney = &v }
248-
func (m *Message) SetPositionEffect(v string) { m.PositionEffect = &v }
249-
func (m *Message) SetText(v string) { m.Text = &v }
250-
func (m *Message) SetEncodedTextLen(v int) { m.EncodedTextLen = &v }
251-
func (m *Message) SetEncodedText(v string) { m.EncodedText = &v }
252-
func (m *Message) SetNumDaysInterest(v int) { m.NumDaysInterest = &v }
253-
func (m *Message) SetAccruedInterestRate(v float64) { m.AccruedInterestRate = &v }
254-
func (m *Message) SetTotalAccruedInterestAmt(v float64) { m.TotalAccruedInterestAmt = &v }
255-
func (m *Message) SetLegalConfirm(v bool) { m.LegalConfirm = &v }
256-
func (m *Message) SetNoAllocs(v []NoAllocs) { m.NoAllocs = v }
223+
func (m *Message) SetAllocID(v string) { m.AllocID = v }
224+
func (m *Message) SetAllocTransType(v string) { m.AllocTransType = v }
225+
func (m *Message) SetAllocType(v int) { m.AllocType = v }
226+
func (m *Message) SetRefAllocID(v string) { m.RefAllocID = &v }
227+
func (m *Message) SetAllocLinkID(v string) { m.AllocLinkID = &v }
228+
func (m *Message) SetAllocLinkType(v int) { m.AllocLinkType = &v }
229+
func (m *Message) SetBookingRefID(v string) { m.BookingRefID = &v }
230+
func (m *Message) SetNoOrders(v []NoOrders) { m.NoOrders = v }
231+
func (m *Message) SetNoExecs(v []NoExecs) { m.NoExecs = v }
232+
func (m *Message) SetSide(v string) { m.Side = v }
233+
func (m *Message) SetInstrument(v instrument.Instrument) { m.Instrument = v }
234+
func (m *Message) SetQuantity(v float64) { m.Quantity = v }
235+
func (m *Message) SetLastMkt(v string) { m.LastMkt = &v }
236+
func (m *Message) SetTradeOriginationDate(v string) { m.TradeOriginationDate = &v }
237+
func (m *Message) SetTradingSessionID(v string) { m.TradingSessionID = &v }
238+
func (m *Message) SetTradingSessionSubID(v string) { m.TradingSessionSubID = &v }
239+
func (m *Message) SetPriceType(v int) { m.PriceType = &v }
240+
func (m *Message) SetAvgPx(v float64) { m.AvgPx = v }
241+
func (m *Message) SetCurrency(v string) { m.Currency = &v }
242+
func (m *Message) SetAvgPrxPrecision(v int) { m.AvgPrxPrecision = &v }
243+
func (m *Message) SetParties(v parties.Parties) { m.Parties = &v }
244+
func (m *Message) SetTradeDate(v string) { m.TradeDate = v }
245+
func (m *Message) SetTransactTime(v time.Time) { m.TransactTime = &v }
246+
func (m *Message) SetSettlmntTyp(v string) { m.SettlmntTyp = &v }
247+
func (m *Message) SetFutSettDate(v string) { m.FutSettDate = &v }
248+
func (m *Message) SetGrossTradeAmt(v float64) { m.GrossTradeAmt = &v }
249+
func (m *Message) SetConcession(v float64) { m.Concession = &v }
250+
func (m *Message) SetTotalTakedown(v float64) { m.TotalTakedown = &v }
251+
func (m *Message) SetNetMoney(v float64) { m.NetMoney = &v }
252+
func (m *Message) SetPositionEffect(v string) { m.PositionEffect = &v }
253+
func (m *Message) SetText(v string) { m.Text = &v }
254+
func (m *Message) SetEncodedTextLen(v int) { m.EncodedTextLen = &v }
255+
func (m *Message) SetEncodedText(v string) { m.EncodedText = &v }
256+
func (m *Message) SetNumDaysInterest(v int) { m.NumDaysInterest = &v }
257+
func (m *Message) SetAccruedInterestRate(v float64) { m.AccruedInterestRate = &v }
258+
func (m *Message) SetTotalAccruedInterestAmt(v float64) { m.TotalAccruedInterestAmt = &v }
259+
func (m *Message) SetLegalConfirm(v bool) { m.LegalConfirm = &v }
260+
func (m *Message) SetNoAllocs(v []NoAllocs) { m.NoAllocs = v }
257261

258262
//A RouteOut is the callback type that should be implemented for routing Message
259263
type RouteOut func(msg Message, sessionID quickfix.SessionID) quickfix.MessageRejectError

0 commit comments

Comments
 (0)