Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion cmd/generate-fix/internal/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ quickfix.GroupTemplate{
{{ if .IsGroup }}
//{{ .Name }} is a repeating group element, Tag {{ .Tag }}
type {{ .Name }} struct {
quickfix.Group
*quickfix.Group
}

{{ template "setters" .}}
Expand Down
8 changes: 4 additions & 4 deletions field.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ type Field interface {
//FieldGroupWriter is an interface for writing a FieldGroup
type FieldGroupWriter interface {
Tag() Tag
Write() TagValues
Write() []TagValue
}

//FieldGroupReader is an interface for reading a FieldGroup
type FieldGroupReader interface {
Tag() Tag
Read(TagValues) (TagValues, error)
Read([]TagValue) ([]TagValue, error)
}

//FieldGroup is the interface implemented by all typed Groups in a Message
type FieldGroup interface {
Tag() Tag
Write() TagValues
Read(TagValues) (TagValues, error)
Write() []TagValue
Read([]TagValue) ([]TagValue, error)
}
94 changes: 59 additions & 35 deletions field_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import (
"time"
)

//FieldMap is a collection of fix fields that make up a fix message.
type FieldMap struct {
tagLookup map[Tag]TagValues
tagOrder
//tagValues stores a slice of TagValues
type tagValues struct {
tvs []TagValue
}

func (f *tagValues) Tag() Tag {
return f.tvs[0].tag
}

// tagOrder true if tag i should occur before tag j
Expand All @@ -24,6 +27,12 @@ func (t tagSort) Len() int { return len(t.tags) }
func (t tagSort) Swap(i, j int) { t.tags[i], t.tags[j] = t.tags[j], t.tags[i] }
func (t tagSort) Less(i, j int) bool { return t.compare(t.tags[i], t.tags[j]) }

//FieldMap is a collection of fix fields that make up a fix message.
type FieldMap struct {
tagLookup map[Tag]*tagValues
tagSort
}

// ascending tags
func normalFieldOrder(i, j Tag) bool { return i < j }

Expand All @@ -32,8 +41,8 @@ func (m *FieldMap) init() {
}

func (m *FieldMap) initWithOrdering(ordering tagOrder) {
m.tagLookup = make(map[Tag]TagValues)
m.tagOrder = ordering
m.tagLookup = make(map[Tag]*tagValues)
m.compare = ordering
}

//Tags returns all of the Field Tags in this FieldMap
Expand Down Expand Up @@ -64,7 +73,7 @@ func (m FieldMap) GetField(tag Tag, parser FieldValueReader) MessageRejectError
return ConditionallyRequiredFieldMissing(tag)
}

if err := parser.Read(tagValues[0].value); err != nil {
if err := parser.Read(tagValues.tvs[0].value); err != nil {
return IncorrectDataFormatForValue(tag)
}

Expand All @@ -78,7 +87,7 @@ func (m FieldMap) GetBytes(tag Tag) ([]byte, MessageRejectError) {
return nil, ConditionallyRequiredFieldMissing(tag)
}

return tagValues[0].value, nil
return tagValues.tvs[0].value, nil
}

//GetBool is a GetField wrapper for bool fields
Expand Down Expand Up @@ -136,7 +145,7 @@ func (m FieldMap) GetGroup(parser FieldGroupReader) MessageRejectError {
return ConditionallyRequiredFieldMissing(parser.Tag())
}

if _, err := parser.Read(tagValues); err != nil {
if _, err := parser.Read(tagValues.tvs); err != nil {
if msgRejErr, ok := err.(MessageRejectError); ok {
return msgRejErr
}
Expand All @@ -147,65 +156,80 @@ func (m FieldMap) GetGroup(parser FieldGroupReader) MessageRejectError {
}

//SetField sets the field with Tag tag
func (m FieldMap) SetField(tag Tag, field FieldValueWriter) FieldMap {
tValues := make(TagValues, 1)
tValues[0].init(tag, field.Write())
m.tagLookup[tag] = tValues
func (m *FieldMap) SetField(tag Tag, field FieldValueWriter) *FieldMap {
tValues := m.getOrCreate(tag)
tValues.tvs = make([]TagValue, 1)
tValues.tvs[0].init(tag, field.Write())
return m
}

//SetBool is a SetField wrapper for bool fields
func (m FieldMap) SetBool(tag Tag, value bool) FieldMap {
func (m *FieldMap) SetBool(tag Tag, value bool) *FieldMap {
return m.SetField(tag, FIXBoolean(value))
}

//SetInt is a SetField wrapper for int fields
func (m FieldMap) SetInt(tag Tag, value int) FieldMap {
func (m *FieldMap) SetInt(tag Tag, value int) *FieldMap {
return m.SetField(tag, FIXInt(value))
}

//SetString is a SetField wrapper for string fields
func (m FieldMap) SetString(tag Tag, value string) FieldMap {
func (m *FieldMap) SetString(tag Tag, value string) *FieldMap {
return m.SetField(tag, FIXString(value))
}

//Clear purges all fields from field map
func (m *FieldMap) Clear() {
m.tags = m.tags[0:0]
for k := range m.tagLookup {
delete(m.tagLookup, k)
}
}

func (m *FieldMap) add(f *tagValues) {
if _, ok := m.tagLookup[f.Tag()]; !ok {
m.tags = append(m.tags, f.Tag())
}

m.tagLookup[f.Tag()] = f
}

func (m *FieldMap) getOrCreate(tag Tag) *tagValues {
if f, ok := m.tagLookup[tag]; ok {
return f
}

f := new(tagValues)
m.tagLookup[tag] = f
m.tags = append(m.tags, tag)
return f
}

//Set is a setter for fields
func (m FieldMap) Set(field FieldWriter) FieldMap {
tValues := make(TagValues, 1)
tValues[0].init(field.Tag(), field.Write())
func (m *FieldMap) Set(field FieldWriter) *FieldMap {
tValues := m.getOrCreate(field.Tag())
tValues.tvs = make([]TagValue, 1)
tValues.tvs[0].init(field.Tag(), field.Write())
m.tagLookup[field.Tag()] = tValues
return m
}

//SetGroup is a setter specific to group fields
func (m FieldMap) SetGroup(field FieldGroupWriter) FieldMap {
m.tagLookup[field.Tag()] = field.Write()
func (m *FieldMap) SetGroup(field FieldGroupWriter) *FieldMap {
f := m.getOrCreate(field.Tag())
f.tvs = field.Write()
return m
}

func (m FieldMap) sortedTags() []Tag {
sortedTags := make([]Tag, len(m.tagLookup))
for tag := range m.tagLookup {
sortedTags = append(sortedTags, tag)
}

sort.Sort(tagSort{sortedTags, m.tagOrder})
return sortedTags
func (m *FieldMap) sortedTags() []Tag {
sort.Sort(m)
return m.tags
}

func (m FieldMap) write(buffer *bytes.Buffer) {
tags := m.sortedTags()

for _, tag := range tags {
for _, tag := range m.sortedTags() {
if fields, ok := m.tagLookup[tag]; ok {
for _, tv := range fields {
for _, tv := range fields.tvs {
buffer.Write(tv.bytes)
}
}
Expand All @@ -215,7 +239,7 @@ func (m FieldMap) write(buffer *bytes.Buffer) {
func (m FieldMap) total() int {
total := 0
for _, fields := range m.tagLookup {
for _, tv := range fields {
for _, tv := range fields.tvs {
switch tv.tag {
case tagCheckSum: //tag does not contribute to total
default:
Expand All @@ -230,7 +254,7 @@ func (m FieldMap) total() int {
func (m FieldMap) length() int {
length := 0
for _, fields := range m.tagLookup {
for _, tv := range fields {
for _, tv := range fields.tvs {
switch tv.tag {
case tagBeginString, tagBodyLength, tagCheckSum: //tags do not contribute to length
default:
Expand Down
8 changes: 4 additions & 4 deletions fix40/allocation/Allocation.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ func (m Allocation) HasNoMiscFees() bool {

//NoOrders is a repeating group element, Tag 73
type NoOrders struct {
quickfix.Group
*quickfix.Group
}

//SetClOrdID sets ClOrdID, Tag 11
Expand Down Expand Up @@ -675,7 +675,7 @@ func (m NoOrdersRepeatingGroup) Get(i int) NoOrders {

//NoAllocs is a repeating group element, Tag 78
type NoAllocs struct {
quickfix.Group
*quickfix.Group
}

//SetAllocAccount sets AllocAccount, Tag 79
Expand Down Expand Up @@ -893,7 +893,7 @@ func (m NoAllocsRepeatingGroup) Get(i int) NoAllocs {

//NoExecs is a repeating group element, Tag 124
type NoExecs struct {
quickfix.Group
*quickfix.Group
}

//SetExecID sets ExecID, Tag 17
Expand Down Expand Up @@ -997,7 +997,7 @@ func (m NoExecsRepeatingGroup) Get(i int) NoExecs {

//NoMiscFees is a repeating group element, Tag 136
type NoMiscFees struct {
quickfix.Group
*quickfix.Group
}

//SetMiscFeeAmt sets MiscFeeAmt, Tag 137
Expand Down
2 changes: 1 addition & 1 deletion fix40/executionreport/ExecutionReport.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ func (m ExecutionReport) HasNoMiscFees() bool {

//NoMiscFees is a repeating group element, Tag 136
type NoMiscFees struct {
quickfix.Group
*quickfix.Group
}

//SetMiscFeeAmt sets MiscFeeAmt, Tag 137
Expand Down
2 changes: 1 addition & 1 deletion fix40/liststatus/ListStatus.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (m ListStatus) HasWaveNo() bool {

//NoOrders is a repeating group element, Tag 73
type NoOrders struct {
quickfix.Group
*quickfix.Group
}

//SetClOrdID sets ClOrdID, Tag 11
Expand Down
8 changes: 4 additions & 4 deletions fix41/allocation/Allocation.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ func (m Allocation) HasSecurityExchange() bool {

//NoOrders is a repeating group element, Tag 73
type NoOrders struct {
quickfix.Group
*quickfix.Group
}

//SetClOrdID sets ClOrdID, Tag 11
Expand Down Expand Up @@ -867,7 +867,7 @@ func (m NoOrdersRepeatingGroup) Get(i int) NoOrders {

//NoAllocs is a repeating group element, Tag 78
type NoAllocs struct {
quickfix.Group
*quickfix.Group
}

//SetAllocAccount sets AllocAccount, Tag 79
Expand Down Expand Up @@ -1250,7 +1250,7 @@ func (m NoAllocs) HasNoMiscFees() bool {

//NoMiscFees is a repeating group element, Tag 136
type NoMiscFees struct {
quickfix.Group
*quickfix.Group
}

//SetMiscFeeAmt sets MiscFeeAmt, Tag 137
Expand Down Expand Up @@ -1358,7 +1358,7 @@ func (m NoAllocsRepeatingGroup) Get(i int) NoAllocs {

//NoExecs is a repeating group element, Tag 124
type NoExecs struct {
quickfix.Group
*quickfix.Group
}

//SetLastShares sets LastShares, Tag 32
Expand Down
4 changes: 2 additions & 2 deletions fix41/email/Email.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (m Email) HasEmailThreadID() bool {

//LinesOfText is a repeating group element, Tag 33
type LinesOfText struct {
quickfix.Group
*quickfix.Group
}

//SetText sets Text, Tag 58
Expand Down Expand Up @@ -295,7 +295,7 @@ func (m LinesOfTextRepeatingGroup) Get(i int) LinesOfText {

//NoRelatedSym is a repeating group element, Tag 146
type NoRelatedSym struct {
quickfix.Group
*quickfix.Group
}

//SetRelatdSym sets RelatdSym, Tag 46
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ func (m IndicationofInterest) HasSecurityExchange() bool {

//NoIOIQualifiers is a repeating group element, Tag 199
type NoIOIQualifiers struct {
quickfix.Group
*quickfix.Group
}

//SetIOIQualifier sets IOIQualifier, Tag 104
Expand Down
2 changes: 1 addition & 1 deletion fix41/liststatus/ListStatus.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (m ListStatus) HasWaveNo() bool {

//NoOrders is a repeating group element, Tag 73
type NoOrders struct {
quickfix.Group
*quickfix.Group
}

//SetClOrdID sets ClOrdID, Tag 11
Expand Down
4 changes: 2 additions & 2 deletions fix41/news/News.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (m News) HasURLLink() bool {

//LinesOfText is a repeating group element, Tag 33
type LinesOfText struct {
quickfix.Group
*quickfix.Group
}

//SetText sets Text, Tag 58
Expand Down Expand Up @@ -255,7 +255,7 @@ func (m LinesOfTextRepeatingGroup) Get(i int) LinesOfText {

//NoRelatedSym is a repeating group element, Tag 146
type NoRelatedSym struct {
quickfix.Group
*quickfix.Group
}

//SetRelatdSym sets RelatdSym, Tag 46
Expand Down
Loading