Skip to content

Commit c5f01ed

Browse files
author
Chris Busbey
committed
fix for #91
1 parent 5fd1988 commit c5f01ed

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

marshal.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func (e encoder) encodeField(f reflect.StructField, t reflect.Type, v reflect.Va
3131
}
3232

3333
func (e encoder) encodeValue(fixTag Tag, v reflect.Value, omitEmpty bool, defaultVal *string) {
34+
3435
if defaultVal != nil {
3536
e.FieldMap.SetField(fixTag, FIXString(*defaultVal))
3637
return
@@ -72,10 +73,18 @@ func (e encoder) encodeValue(fixTag Tag, v reflect.Value, omitEmpty bool, defaul
7273
walkFunc = func(t reflect.Type) {
7374
for i := 0; i < t.NumField(); i++ {
7475
sf := t.Field(i)
75-
if sf.Anonymous {
76-
walkFunc(sf.Type)
76+
77+
//recurse if item is a component, optional or not
78+
elementType := sf.Type
79+
if elementType.Kind() == reflect.Ptr {
80+
elementType = elementType.Elem()
81+
}
82+
83+
if elementType.Kind() == reflect.Struct {
84+
walkFunc(elementType)
7785
continue
7886
}
87+
7988
afixTag, err := strconv.Atoi(strings.Split(sf.Tag.Get("fix"), ",")[0])
8089

8190
if err != nil {

marshal_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package quickfix_test
22

33
import (
44
"bytes"
5-
"github.com/quickfixgo/quickfix"
6-
"github.com/quickfixgo/quickfix/field"
75
"testing"
86
"time"
7+
8+
"github.com/quickfixgo/quickfix"
9+
"github.com/quickfixgo/quickfix/field"
910
)
1011

1112
func TestMarshal_FIXMsgType(t *testing.T) {
@@ -183,10 +184,18 @@ func TestMarshal_RepeatingGroups(t *testing.T) {
183184
IntField3 int `fix:"3"`
184185
}
185186

187+
type GroupComponent1 struct {
188+
}
189+
190+
type GroupComponent2 struct {
191+
}
192+
186193
type Group2 struct {
187194
IntField1 int `fix:"1"`
188195
IntField2 int `fix:"2, omitempty"`
189196
AnonymousGroup
197+
GroupComponent1
198+
OptionalComponent *GroupComponent2
190199
}
191200

192201
type Message struct {

0 commit comments

Comments
 (0)