Skip to content

Commit

Permalink
update comment
Browse files Browse the repository at this point in the history
  • Loading branch information
mfdeveloper508 committed Oct 5, 2023
1 parent cc051aa commit dc61226
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions field/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,14 @@ func (f *Composite) Unmarshal(v interface{}) error {
return fmt.Errorf("failed to get data from field %s: %w", indexOrTag, err)
}
default: // Native types
vv := reflect.New(dataField.Type()).Elem()
err = messageField.Unmarshal(vv)
// using new reflect value that has pointer instead of input data field
dummy := reflect.New(dataField.Type()).Elem()
err = messageField.Unmarshal(dummy)
if err != nil {
return fmt.Errorf("failed to get data from field %s: %w", indexOrTag, err)
}
dataField.Set(vv)

dataField.Set(dummy)
}
}

Expand Down
8 changes: 5 additions & 3 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,12 +513,14 @@ func (m *Message) Unmarshal(v interface{}) error {
return fmt.Errorf("failed to get value from field %d: %w", fieldIndex, err)
}
default: // Native types
vv := reflect.New(dataField.Type()).Elem()
err = messageField.Unmarshal(vv)
// using new reflect value that has pointer instead of input data field
dummy := reflect.New(dataField.Type()).Elem()
err = messageField.Unmarshal(dummy)
if err != nil {
return fmt.Errorf("failed to get value from field %d: %w", fieldIndex, err)
}
dataField.Set(vv)

dataField.Set(dummy)
}
}

Expand Down

0 comments on commit dc61226

Please sign in to comment.