Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue 214 #216

Merged
merged 1 commit into from
Aug 6, 2020
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
8 changes: 8 additions & 0 deletions binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ import (
perrors "github.com/pkg/errors"
)

// binaryTag check whether the given tag is a binary tag
func binaryTag(tag byte) bool {
return (tag >= BC_BINARY_DIRECT && tag <= INT_DIRECT_MAX) ||
(tag >= BC_BINARY_SHORT && tag <= byte(0x37)) ||
tag == BC_BINARY_CHUNK ||
tag == BC_BINARY
}

/////////////////////////////////////////
// Binary, []byte
/////////////////////////////////////////
Expand Down
45 changes: 45 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@
package hessian

import (
"fmt"
"log"
"os"
"os/exec"
"reflect"
"testing"
)

import (
"github.com/stretchr/testify/assert"
)

import (
"github.com/apache/dubbo-go-hessian2/java_exception"
)
Expand Down Expand Up @@ -145,3 +151,42 @@ func TestUserDefindeException(t *testing.T) {
}
testDecodeFramework(t, "throw_UserDefindException", expect)
}

type Circular214 struct {
Num int
Previous *Circular214
Next *Circular214
Bytes []byte
}

func (Circular214) JavaClassName() string {
return "com.company.Circular"
}

func (c *Circular214) String() string {
return fmt.Sprintf("Addr:%p, Num: %d, Previous: %p, Next: %p, Bytes: %s", c, c.Num, c.Previous, c.Next, c.Bytes)
}

func TestIssue214(t *testing.T) {
c := &Circular214{}
c.Num = 1234
c.Previous = c
c.Next = c
c.Bytes = []byte(`{"a":"b"}`)
e := NewEncoder()
err := e.Encode(c)
if err != nil {
assert.FailNow(t, fmt.Sprintf("%v", err))
return
}

bytes := e.Buffer()
decoder := NewDecoder(bytes)
decode, err := decoder.Decode()
if err != nil {
assert.FailNow(t, fmt.Sprintf("%v", err))
return
}
t.Log(decode)
assert.True(t, reflect.DeepEqual(c, decode))
}
2 changes: 2 additions & 0 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ func (d *Decoder) decList(flag int32) (interface{}, error) {
return d.readTypedList(tag)
case untypedListTag(tag):
return d.readUntypedList(tag)
case binaryTag(tag):
return d.decBinary(int32(tag))
default:
return nil, perrors.Errorf("error list tag: 0x%x", tag)
}
Expand Down