Skip to content

Commit

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

dataField.Set(dummy)
}
}

Expand Down
2 changes: 1 addition & 1 deletion field/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (f *String) Unmarshal(v interface{}) error {
}

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

dataField.Set(dummy)
}
}

Expand Down

0 comments on commit 62da169

Please sign in to comment.