Repository: apache/dubbo-go-hessian2
Pull request #225 (2020-09-05 12:26:02)

Export some function
As the title.


Patch:
diff --git a/encode.go b/encode.go
index ad9d5c6..2ae6791 100644
--- a/encode.go
+++ b/encode.go
@@ -61,13 +61,13 @@ func (e *Encoder) Append(buf []byte) {
 // Encode If @v can not be encoded, the return value is nil. At present only struct may can not be encoded.
 func (e *Encoder) Encode(v interface{}) error {
 	if v == nil {
-		e.buffer = encNull(e.buffer)
+		e.buffer = EncNull(e.buffer)
 		return nil
 	}
 
 	switch val := v.(type) {
 	case nil:
-		e.buffer = encNull(e.buffer)
+		e.buffer = EncNull(e.buffer)
 		return nil
 
 	case bool:
@@ -105,7 +105,7 @@ func (e *Encoder) Encode(v interface{}) error {
 
 	case time.Time:
 		if ZeroDate == val {
-			e.buffer = encNull(e.buffer)
+			e.buffer = EncNull(e.buffer)
 		} else {
 			e.buffer = encDateInMs(e.buffer, &val)
 			// e.buffer = encDateInMimute(v.(time.Time), e.buffer)
@@ -138,7 +138,7 @@ func (e *Encoder) Encode(v interface{}) error {
 			vv := reflect.ValueOf(v)
 			vv = UnpackPtr(vv)
 			if !vv.IsValid() {
-				e.buffer = encNull(e.buffer)
+				e.buffer = EncNull(e.buffer)
 				return nil
 			}
 			if vv.Type().String() == "time.Time" {
diff --git a/int.go b/int.go
index 5263a3f..0581170 100644
--- a/int.go
+++ b/int.go
@@ -110,7 +110,7 @@ func (d *Decoder) decInt32(flag int32) (int32, error) {
 func (d *Encoder) encTypeInt32(b []byte, p interface{}) ([]byte, error) {
 	value := reflect.ValueOf(p)
 	if PackPtr(value).IsNil() {
-		return encNull(b), nil
+		return EncNull(b), nil
 	}
 	value = UnpackPtrValue(value)
 	if value.Kind() != reflect.Int32 {
diff --git a/map.go b/map.go
index 1b958c4..feec8fa 100644
--- a/map.go
+++ b/map.go
@@ -113,14 +113,14 @@ func (e *Encoder) encMap(m interface{}) error {
 	value = UnpackPtrValue(value)
 	// check nil map
 	if value.Kind() == reflect.Ptr && !value.Elem().IsValid() {
-		e.buffer = encNull(e.buffer)
+		e.buffer = EncNull(e.buffer)
 		return nil
 	}
 
 	keys = value.MapKeys()
 	if len(keys) == 0 {
 		// fix: set nil for empty map
-		e.buffer = encNull(e.buffer)
+		e.buffer = EncNull(e.buffer)
 		return nil
 	}
 
diff --git a/null.go b/null.go
index 0b1fd7f..8d74d1b 100644
--- a/null.go
+++ b/null.go
@@ -20,6 +20,6 @@ package hessian
 /////////////////////////////////////////
 // Null
 /////////////////////////////////////////
-func encNull(b []byte) []byte {
+func EncNull(b []byte) []byte {
 	return append(b, BC_NULL)
 }
diff --git a/object.go b/object.go
index 9148dfa..dcd8130 100644
--- a/object.go
+++ b/object.go
@@ -117,7 +117,7 @@ func (e *Encoder) encObject(v POJO) error {
 	vv = UnpackPtr(vv)
 	// check nil pointer
 	if !vv.IsValid() {
-		e.buffer = encNull(e.buffer)
+		e.buffer = EncNull(e.buffer)
 		return nil
 	}
 
diff --git a/pojo.go b/pojo.go
index be74bac..bf11633 100644
--- a/pojo.go
+++ b/pojo.go
@@ -206,8 +206,8 @@ func RegisterPOJO(o POJO) int {
 	return structInfo.index
 }
 
-// easy for test
-func unRegisterPOJOs(os ...POJO) []int {
+// UnRegisterPOJOs unregister POJO instances. It is easy for test.
+func UnRegisterPOJOs(os ...POJO) []int {
 	arr := make([]int, len(os))
 	for i := range os {
 		arr[i] = unRegisterPOJO(os[i])
diff --git a/response.go b/response.go
index ea7408f..68f7c6b 100644
--- a/response.go
+++ b/response.go
@@ -140,7 +140,7 @@ func packResponse(header DubboHeader, ret interface{}) ([]byte, error) {
 	}
 
 	byteArray = encoder.Buffer()
-	byteArray = encNull(byteArray) // if not, "java client" will throw exception  "unexpected end of file"
+	byteArray = EncNull(byteArray) // if not, "java client" will throw exception  "unexpected end of file"
 	pkgLen := len(byteArray)
 	if pkgLen > int(DEFAULT_LEN) { // 8M
 		return nil, perrors.Errorf("Data length %d too large, max payload %d", pkgLen, DEFAULT_LEN)


Test patch:
diff --git a/hessian_test.go b/hessian_test.go
index 47726a2..b712838 100644
--- a/hessian_test.go
+++ b/hessian_test.go
@@ -199,7 +199,7 @@ func TestHessianCodec_ReadAttachments(t *testing.T) {
 	}
 	resp, err := doTestHessianEncodeHeader(t, PackageResponse, Response_OK, body)
 	assert.NoError(t, err)
-	unRegisterPOJOs(&CaseB{}, &CaseA{})
+	UnRegisterPOJOs(&CaseB{}, &CaseA{})
 	codecR1 := NewHessianCodec(bufio.NewReader(bytes.NewReader(resp)))
 	codecR2 := NewHessianCodec(bufio.NewReader(bytes.NewReader(resp)))
 	h := &DubboHeader{}