This is an automated email from the ASF dual-hosted git repository.

wongoo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-go-hessian2.git


The following commit(s) were added to refs/heads/master by this push:
     new 9e91fc9  fix issue 214 (#216)
9e91fc9 is described below

commit 9e91fc9a7de335e427999bd3cd9cd60ef0304169
Author: 望哥 <[email protected]>
AuthorDate: Thu Aug 6 15:14:44 2020 +0800

    fix issue 214 (#216)
---
 binary.go      |  8 ++++++++
 decode_test.go | 45 +++++++++++++++++++++++++++++++++++++++++++++
 list.go        |  2 ++
 3 files changed, 55 insertions(+)

diff --git a/binary.go b/binary.go
index 1cdea45..a30af8d 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 30468d7..87f4604 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 87aef90..0eed874 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)
        }

Reply via email to