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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (e encoder) encodeField(f reflect.StructField, t reflect.Type, v reflect.Va
}

func (e encoder) encodeValue(fixTag Tag, v reflect.Value, omitEmpty bool, defaultVal *string) {

if defaultVal != nil {
e.FieldMap.SetField(fixTag, FIXString(*defaultVal))
return
Expand Down Expand Up @@ -72,10 +73,18 @@ func (e encoder) encodeValue(fixTag Tag, v reflect.Value, omitEmpty bool, defaul
walkFunc = func(t reflect.Type) {
for i := 0; i < t.NumField(); i++ {
sf := t.Field(i)
if sf.Anonymous {
walkFunc(sf.Type)

//recurse if item is a component, optional or not
elementType := sf.Type
if elementType.Kind() == reflect.Ptr {
elementType = elementType.Elem()
}

if elementType.Kind() == reflect.Struct {
walkFunc(elementType)
continue
}

afixTag, err := strconv.Atoi(strings.Split(sf.Tag.Get("fix"), ",")[0])

if err != nil {
Expand Down
13 changes: 11 additions & 2 deletions marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package quickfix_test

import (
"bytes"
"github.com/quickfixgo/quickfix"
"github.com/quickfixgo/quickfix/field"
"testing"
"time"

"github.com/quickfixgo/quickfix"
"github.com/quickfixgo/quickfix/field"
)

func TestMarshal_FIXMsgType(t *testing.T) {
Expand Down Expand Up @@ -183,10 +184,18 @@ func TestMarshal_RepeatingGroups(t *testing.T) {
IntField3 int `fix:"3"`
}

type GroupComponent1 struct {
}

type GroupComponent2 struct {
}

type Group2 struct {
IntField1 int `fix:"1"`
IntField2 int `fix:"2, omitempty"`
AnonymousGroup
GroupComponent1
OptionalComponent *GroupComponent2
}

type Message struct {
Expand Down