@@ -6,15 +6,26 @@ import (
66 "time"
77)
88
9- //tagValues stores a slice of TagValues
10- type tagValues struct {
9+ //field stores a slice of TagValues
10+ type field struct {
1111 tvs []TagValue
1212}
1313
14- func (f * tagValues ) Tag () Tag {
14+ func (f * field ) Tag () Tag {
1515 return f .tvs [0 ].tag
1616}
1717
18+ func (f * field ) init (tag Tag , value []byte ) {
19+ f .tvs = make ([]TagValue , 1 )
20+ f .tvs [0 ].init (tag , value )
21+ }
22+
23+ func (f * field ) write (buffer * bytes.Buffer ) {
24+ for _ , tv := range f .tvs {
25+ buffer .Write (tv .bytes )
26+ }
27+ }
28+
1829// tagOrder true if tag i should occur before tag j
1930type tagOrder func (i , j Tag ) bool
2031
@@ -29,7 +40,7 @@ func (t tagSort) Less(i, j int) bool { return t.compare(t.tags[i], t.tags[j]) }
2940
3041//FieldMap is a collection of fix fields that make up a fix message.
3142type FieldMap struct {
32- tagLookup map [Tag ]* tagValues
43+ tagLookup map [Tag ]* field
3344 tagSort
3445}
3546
@@ -41,7 +52,7 @@ func (m *FieldMap) init() {
4152}
4253
4354func (m * FieldMap ) initWithOrdering (ordering tagOrder ) {
44- m .tagLookup = make (map [Tag ]* tagValues )
55+ m .tagLookup = make (map [Tag ]* field )
4556 m .compare = ordering
4657}
4758
@@ -68,12 +79,12 @@ func (m FieldMap) Has(tag Tag) bool {
6879
6980//GetField parses of a field with Tag tag. Returned reject may indicate the field is not present, or the field value is invalid.
7081func (m FieldMap ) GetField (tag Tag , parser FieldValueReader ) MessageRejectError {
71- tagValues , ok := m .tagLookup [tag ]
82+ f , ok := m .tagLookup [tag ]
7283 if ! ok {
7384 return ConditionallyRequiredFieldMissing (tag )
7485 }
7586
76- if err := parser .Read (tagValues .tvs [0 ].value ); err != nil {
87+ if err := parser .Read (f .tvs [0 ].value ); err != nil {
7788 return IncorrectDataFormatForValue (tag )
7889 }
7990
@@ -82,12 +93,12 @@ func (m FieldMap) GetField(tag Tag, parser FieldValueReader) MessageRejectError
8293
8394//GetBytes is a zero-copy GetField wrapper for []bytes fields
8495func (m FieldMap ) GetBytes (tag Tag ) ([]byte , MessageRejectError ) {
85- tagValues , ok := m .tagLookup [tag ]
96+ f , ok := m .tagLookup [tag ]
8697 if ! ok {
8798 return nil , ConditionallyRequiredFieldMissing (tag )
8899 }
89100
90- return tagValues .tvs [0 ].value , nil
101+ return f .tvs [0 ].value , nil
91102}
92103
93104//GetBool is a GetField wrapper for bool fields
@@ -140,12 +151,12 @@ func (m FieldMap) GetString(tag Tag) (string, MessageRejectError) {
140151
141152//GetGroup is a Get function specific to Group Fields.
142153func (m FieldMap ) GetGroup (parser FieldGroupReader ) MessageRejectError {
143- tagValues , ok := m .tagLookup [parser .Tag ()]
154+ f , ok := m .tagLookup [parser .Tag ()]
144155 if ! ok {
145156 return ConditionallyRequiredFieldMissing (parser .Tag ())
146157 }
147158
148- if _ , err := parser .Read (tagValues .tvs ); err != nil {
159+ if _ , err := parser .Read (f .tvs ); err != nil {
149160 if msgRejErr , ok := err .(MessageRejectError ); ok {
150161 return msgRejErr
151162 }
@@ -157,9 +168,8 @@ func (m FieldMap) GetGroup(parser FieldGroupReader) MessageRejectError {
157168
158169//SetField sets the field with Tag tag
159170func (m * FieldMap ) SetField (tag Tag , field FieldValueWriter ) * FieldMap {
160- tValues := m .getOrCreate (tag )
161- tValues .tvs = make ([]TagValue , 1 )
162- tValues .tvs [0 ].init (tag , field .Write ())
171+ f := m .getOrCreate (tag )
172+ f .init (tag , field .Write ())
163173 return m
164174}
165175
@@ -186,31 +196,29 @@ func (m *FieldMap) Clear() {
186196 }
187197}
188198
189- func (m * FieldMap ) add (f * tagValues ) {
199+ func (m * FieldMap ) add (f * field ) {
190200 if _ , ok := m .tagLookup [f .Tag ()]; ! ok {
191201 m .tags = append (m .tags , f .Tag ())
192202 }
193203
194204 m .tagLookup [f .Tag ()] = f
195205}
196206
197- func (m * FieldMap ) getOrCreate (tag Tag ) * tagValues {
207+ func (m * FieldMap ) getOrCreate (tag Tag ) * field {
198208 if f , ok := m .tagLookup [tag ]; ok {
199209 return f
200210 }
201211
202- f := new (tagValues )
212+ f := new (field )
203213 m .tagLookup [tag ] = f
204214 m .tags = append (m .tags , tag )
205215 return f
206216}
207217
208218//Set is a setter for fields
209219func (m * FieldMap ) Set (field FieldWriter ) * FieldMap {
210- tValues := m .getOrCreate (field .Tag ())
211- tValues .tvs = make ([]TagValue , 1 )
212- tValues .tvs [0 ].init (field .Tag (), field .Write ())
213- m .tagLookup [field .Tag ()] = tValues
220+ f := m .getOrCreate (field .Tag ())
221+ f .init (field .Tag (), field .Write ())
214222 return m
215223}
216224
@@ -228,10 +236,8 @@ func (m *FieldMap) sortedTags() []Tag {
228236
229237func (m FieldMap ) write (buffer * bytes.Buffer ) {
230238 for _ , tag := range m .sortedTags () {
231- if fields , ok := m .tagLookup [tag ]; ok {
232- for _ , tv := range fields .tvs {
233- buffer .Write (tv .bytes )
234- }
239+ if f , ok := m .tagLookup [tag ]; ok {
240+ f .write (buffer )
235241 }
236242 }
237243}
0 commit comments