Skip to content

Commit

Permalink
Merge pull request #41 from Iceber/unmarshal
Browse files Browse the repository at this point in the history
unmarshal does not return nil object when value is nil
  • Loading branch information
kzys authored Apr 26, 2023
2 parents 2a94991 + 5278571 commit 7ef6316
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 25 deletions.
4 changes: 0 additions & 4 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,6 @@ func UnmarshalToByTypeURL(typeURL string, value []byte, out interface{}) error {
}

func unmarshal(typeURL string, value []byte, v interface{}) (interface{}, error) {
if value == nil {
return nil, nil
}

t, err := getTypeByUrl(typeURL)
if err != nil {
return nil, err
Expand Down
21 changes: 0 additions & 21 deletions types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,27 +195,6 @@ func TestRegisterDiffUrls(t *testing.T) {
Register(&test{}, "test", "two")
}

func TestUnmarshalNil(t *testing.T) {
var pba *anypb.Any // This is nil.
var a Any = pba // This is typed nil.

if pba != nil {
t.Fatal("pbany must be nil")
}
if a == nil {
t.Fatal("nilany must not be nil")
}

actual, err := UnmarshalAny(a)
if err != nil {
t.Fatal(err)
}

if actual != nil {
t.Fatalf("expected nil, got %v", actual)
}
}

func TestCheckNil(t *testing.T) {
var a *anyType

Expand Down

0 comments on commit 7ef6316

Please sign in to comment.