Skip to content

Commit 3ff29f9

Browse files
author
Chris Busbey
committed
generates NewHeader for BeginString
1 parent 1e65673 commit 3ff29f9

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

cmd/generate-fix/generate-fix.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func genHeader(pkg string, spec *datadictionary.DataDictionary) {
5959
Package: pkg,
6060
Name: "Header",
6161
MessageDef: spec.Header,
62+
FIXSpec: spec,
6263
}
6364
if err := internal.HeaderTemplate.Execute(writer, c); err != nil {
6465
errors <- err

cmd/generate-fix/internal/template_helpers.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ func requiredFields(m *datadictionary.MessageDef) (required []*datadictionary.Fi
171171
return
172172
}
173173

174+
func beginString(spec *datadictionary.DataDictionary) string {
175+
if spec.FIXType == "FIXT" || spec.Major == 5 {
176+
return "FIXT.1.1"
177+
}
178+
179+
return fmt.Sprintf("FIX.%v.%v", spec.Major, spec.Minor)
180+
}
181+
174182
func routerBeginString(spec *datadictionary.DataDictionary) (routerBeginString string) {
175183
switch {
176184
case spec.FIXType == "FIXT":

cmd/generate-fix/internal/templates.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func init() {
1818
tmplFuncs := template.FuncMap{
1919
"toLower": strings.ToLower,
2020
"requiredFields": requiredFields,
21+
"beginString": beginString,
2122
"routerBeginString": routerBeginString,
2223
"importRootPath": getImportPathRoot,
2324
"quickfixType": quickfixType,
@@ -146,6 +147,13 @@ type Header struct {
146147
quickfix.Header
147148
}
148149
150+
//NewHeader returns a new, initialized Header instance
151+
func NewHeader() (h Header) {
152+
h.Init()
153+
h.SetBeginString("{{ beginString .FIXSpec }}")
154+
return
155+
}
156+
149157
{{ template "setters" .}}
150158
{{ template "getters" . }}
151159
{{ template "hasers" . }}
@@ -222,7 +230,7 @@ func (m {{ .Name }}) ToMessage() quickfix.Message {
222230
{{ $required_fields := requiredFields .MessageDef -}}
223231
//New returns a {{ .Name }} initialized with the required fields for {{ .Name }}
224232
func New({{template "field_args" $required_fields }}) (m {{ .Name }}) {
225-
m.Header.Init()
233+
m.Header = {{ .TransportPackage }}.NewHeader()
226234
m.Init()
227235
m.Trailer.Init()
228236

0 commit comments

Comments
 (0)