Skip to content

Commit c4ab5d6

Browse files
author
Chris Busbey
committed
setters for repeating groups, dry on gen code
1 parent 2967c01 commit c4ab5d6

File tree

441 files changed

+4651
-34
lines changed

Some content is hidden

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

441 files changed

+4651
-34
lines changed

_gen/generate-components/main.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,14 @@ func collectGroups(parent string, part datadictionary.MessagePart, groups []grou
5353
return groups
5454
}
5555

56-
func genGroupDeclaration(field *datadictionary.FieldDef, parent string) (fileOut string) {
57-
fileOut += fmt.Sprintf("//%v is a repeating group in %v\n", field.Name(), parent)
58-
fileOut += fmt.Sprintf("type %v struct {\n", field.Name())
59-
fileOut += gen.WriteFieldDeclarations(fixSpec.Major, fixSpec.Minor, field.Parts, field.Name())
60-
61-
fileOut += "}\n"
62-
63-
return
64-
}
65-
6656
func genGroupDeclarations(name string, fields []datadictionary.MessagePart) (fileOut string) {
6757
groups := []group{}
6858
for _, field := range fields {
6959
groups = collectGroups(name, field, groups)
7060
}
7161

7262
for _, group := range groups {
73-
fileOut += genGroupDeclaration(group.field, group.parent)
63+
fileOut += gen.WriteGroupDeclaration(fixSpec.Major, fixSpec.Minor, group.field, group.parent)
7464
}
7565

7666
return

_gen/generate-messages/main.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,6 @@ func genMessages() {
4040
}
4141
}
4242

43-
func genGroupDeclaration(field *datadictionary.FieldDef, parent string) (fileOut string) {
44-
fileOut += fmt.Sprintf("//%v is a repeating group in %v\n", field.Name(), parent)
45-
fileOut += fmt.Sprintf("type %v struct {\n", field.Name())
46-
fileOut += gen.WriteFieldDeclarations(fixSpec.Major, fixSpec.Minor, field.Parts, field.Name())
47-
48-
fileOut += "}\n"
49-
50-
writer := new(bytes.Buffer)
51-
if err := gen.WriteFieldSetters(writer, field.Name(), field.Parts); err != nil {
52-
panic(err)
53-
}
54-
fileOut += writer.String()
55-
fileOut += "\n"
56-
57-
return
58-
}
59-
6043
type group struct {
6144
parent string
6245
field *datadictionary.FieldDef
@@ -85,7 +68,7 @@ func genGroupDeclarations(msg *datadictionary.MessageDef) (fileOut string) {
8568
}
8669

8770
for _, group := range groups {
88-
fileOut += genGroupDeclaration(group.field, group.parent)
71+
fileOut += gen.WriteGroupDeclaration(fixSpec.Major, fixSpec.Minor, group.field, group.parent)
8972
}
9073

9174
return

_gen/helpers.go

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

33
import (
4+
"bytes"
45
"fmt"
56
"io"
67
"strconv"
@@ -163,6 +164,23 @@ func WriteFieldDeclarations(fixSpecMajor int, fixSpecMinor int, parts []datadict
163164
return
164165
}
165166

167+
func WriteGroupDeclaration(fixSpecMajor, fixSpecMinor int, field *datadictionary.FieldDef, parent string) (fileOut string) {
168+
fileOut += fmt.Sprintf("//%v is a repeating group in %v\n", field.Name(), parent)
169+
fileOut += fmt.Sprintf("type %v struct {\n", field.Name())
170+
fileOut += WriteFieldDeclarations(fixSpecMajor, fixSpecMinor, field.Parts, field.Name())
171+
172+
fileOut += "}\n"
173+
174+
writer := new(bytes.Buffer)
175+
if err := WriteFieldSetters(writer, field.Name(), field.Parts); err != nil {
176+
panic(err)
177+
}
178+
fileOut += writer.String()
179+
fileOut += "\n"
180+
181+
return
182+
}
183+
166184
func writeFieldDeclaration(fixSpecMajor int, fixSpecMinor int, part datadictionary.MessagePart, componentName string) (s string) {
167185
switch field := part.(type) {
168186
case datadictionary.Component:

datadictionary/build.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ func (b builder) buildMessageDef(xmlMessage *XMLComponent) (*MessageDef, error)
174174

175175
func (b builder) buildGroupFieldDef(xmlField *XMLComponentMember, groupFieldType *FieldType) (*FieldDef, error) {
176176
var parts []MessagePart
177-
var fields []*FieldDef
178177

179178
for _, member := range xmlField.Members {
180179
if member.XMLName.Local == "component" {
@@ -190,19 +189,17 @@ func (b builder) buildGroupFieldDef(xmlField *XMLComponentMember, groupFieldType
190189
}
191190

192191
parts = append(parts, comp)
193-
fields = append(fields, comp.Fields()...)
194192
} else {
195193
var f *FieldDef
196194
var err error
197195
if f, err = b.buildFieldDef(member); err != nil {
198196
return nil, err
199197
}
200198
parts = append(parts, f)
201-
fields = append(fields, f)
202199
}
203200
}
204201

205-
return &FieldDef{FieldType: groupFieldType, required: (xmlField.Required == "Y"), Parts: parts, ChildFields: fields}, nil
202+
return NewGroupFieldDef(groupFieldType, (xmlField.Required == "Y"), parts), nil
206203
}
207204

208205
func (b builder) buildFieldDef(xmlField *XMLComponentMember) (*FieldDef, error) {
@@ -218,7 +215,7 @@ func (b builder) buildFieldDef(xmlField *XMLComponentMember) (*FieldDef, error)
218215
return f, err
219216
}
220217

221-
return &FieldDef{FieldType: fieldType, required: (xmlField.Required == "Y")}, nil
218+
return NewFieldDef(fieldType, (xmlField.Required == "Y")), nil
222219
}
223220

224221
func (b builder) buildFieldTypes() {

datadictionary/datadictionary.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,37 @@ type FieldDef struct {
110110
ChildFields []*FieldDef
111111
}
112112

113+
//NewFieldDef returns an initialized FieldDef
114+
func NewFieldDef(fieldType *FieldType, required bool) *FieldDef {
115+
return &FieldDef{
116+
FieldType: fieldType,
117+
required: required,
118+
}
119+
}
120+
121+
//NewGroupFieldDef returns an initialized FieldDef for a repeating group
122+
func NewGroupFieldDef(fieldType *FieldType, required bool, parts []MessagePart) *FieldDef {
123+
field := FieldDef{
124+
FieldType: fieldType,
125+
required: required,
126+
Parts: parts,
127+
}
128+
129+
for _, part := range parts {
130+
if comp, ok := part.(Component); ok {
131+
field.ChildFields = append(field.ChildFields, comp.Fields()...)
132+
} else {
133+
if child, ok := part.(*FieldDef); ok {
134+
field.ChildFields = append(field.ChildFields, child)
135+
} else {
136+
panic("unknown part")
137+
}
138+
}
139+
}
140+
141+
return &field
142+
}
143+
113144
//Required returns true if this FieldDef is required for the containing
114145
//MessageDef
115146
func (f FieldDef) Required() bool { return f.required }

fix43/header.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ type NoHops struct {
1414
HopRefID *int `fix:"630"`
1515
}
1616

17+
func (m *NoHops) SetHopCompID(v string) { m.HopCompID = &v }
18+
func (m *NoHops) SetHopSendingTime(v time.Time) { m.HopSendingTime = &v }
19+
func (m *NoHops) SetHopRefID(v int) { m.HopRefID = &v }
20+
1721
//Header is the fix43 Header type
1822
type Header struct {
1923
//BeginString is a required field for Header.

fix43/instrument/Instrument.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ type NoSecurityAltID struct {
1313
SecurityAltIDSource *string `fix:"456"`
1414
}
1515

16+
func (m *NoSecurityAltID) SetSecurityAltID(v string) { m.SecurityAltID = &v }
17+
func (m *NoSecurityAltID) SetSecurityAltIDSource(v string) { m.SecurityAltIDSource = &v }
18+
1619
//Instrument is a fix43 Component
1720
type Instrument struct {
1821
//Symbol is a non-required field for Instrument.

fix43/instrumentleg/InstrumentLeg.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ type NoLegSecurityAltID struct {
1313
LegSecurityAltIDSource *string `fix:"606"`
1414
}
1515

16+
func (m *NoLegSecurityAltID) SetLegSecurityAltID(v string) { m.LegSecurityAltID = &v }
17+
func (m *NoLegSecurityAltID) SetLegSecurityAltIDSource(v string) { m.LegSecurityAltIDSource = &v }
18+
1619
//InstrumentLeg is a fix43 Component
1720
type InstrumentLeg struct {
1821
//LegSymbol is a non-required field for InstrumentLeg.

fix43/nestedparties/NestedParties.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ type NoNestedPartyIDs struct {
1717
NestedPartySubID *string `fix:"545"`
1818
}
1919

20+
func (m *NoNestedPartyIDs) SetNestedPartyID(v string) { m.NestedPartyID = &v }
21+
func (m *NoNestedPartyIDs) SetNestedPartyIDSource(v string) { m.NestedPartyIDSource = &v }
22+
func (m *NoNestedPartyIDs) SetNestedPartyRole(v int) { m.NestedPartyRole = &v }
23+
func (m *NoNestedPartyIDs) SetNestedPartySubID(v string) { m.NestedPartySubID = &v }
24+
2025
//NestedParties is a fix43 Component
2126
type NestedParties struct {
2227
//NoNestedPartyIDs is a non-required field for NestedParties.

fix43/parties/Parties.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ type NoPartyIDs struct {
1717
PartySubID *string `fix:"523"`
1818
}
1919

20+
func (m *NoPartyIDs) SetPartyID(v string) { m.PartyID = &v }
21+
func (m *NoPartyIDs) SetPartyIDSource(v string) { m.PartyIDSource = &v }
22+
func (m *NoPartyIDs) SetPartyRole(v int) { m.PartyRole = &v }
23+
func (m *NoPartyIDs) SetPartySubID(v string) { m.PartySubID = &v }
24+
2025
//Parties is a fix43 Component
2126
type Parties struct {
2227
//NoPartyIDs is a non-required field for Parties.

0 commit comments

Comments
 (0)