diff --git a/binary.go b/binary.go index 1cdea459..a30af8da 100644 --- a/binary.go +++ b/binary.go @@ -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 ///////////////////////////////////////// diff --git a/decode_test.go b/decode_test.go index 30468d7c..87f46040 100644 --- a/decode_test.go +++ b/decode_test.go @@ -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" ) @@ -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)) +} diff --git a/list.go b/list.go index 87aef906..0eed8747 100644 --- a/list.go +++ b/list.go @@ -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) }