You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by di...@apache.org on 2019/08/23 07:39:25 UTC
[rocketmq-client-go] branch native updated: [ISSUE #164]add
UnCompress function implementation (#167)
This is an automated email from the ASF dual-hosted git repository.
dinglei pushed a commit to branch native
in repository https://gitbox.apache.org/repos/asf/rocketmq-client-go.git
The following commit(s) were added to refs/heads/native by this push:
new e572801 [ISSUE #164]add UnCompress function implementation (#167)
e572801 is described below
commit e572801dd746d6cae4e577d0edd5b45d4b63cccc
Author: kelly-fan <ke...@users.noreply.github.com>
AuthorDate: Fri Aug 23 15:39:20 2019 +0800
[ISSUE #164]add UnCompress function implementation (#167)
Add UnCompress function implementation
---
internal/utils/helper.go | 17 ++++++++++++++++-
internal/utils/{helper.go => helper_test.go} | 21 ++++++++++++++++-----
2 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/internal/utils/helper.go b/internal/utils/helper.go
index 58ea791..7215d92 100644
--- a/internal/utils/helper.go
+++ b/internal/utils/helper.go
@@ -17,10 +17,25 @@ limitations under the License.
package utils
+import (
+ "bytes"
+ "compress/zlib"
+ "io/ioutil"
+)
+
func GetAddressByBytes(data []byte) string {
return "127.0.0.1"
}
func UnCompress(data []byte) []byte {
- return data
+ rdata := bytes.NewReader(data)
+ r, err := zlib.NewReader(rdata)
+ if err != nil {
+ return data
+ }
+ retData, err := ioutil.ReadAll(r)
+ if err != nil {
+ return data
+ }
+ return retData
}
diff --git a/internal/utils/helper.go b/internal/utils/helper_test.go
similarity index 68%
copy from internal/utils/helper.go
copy to internal/utils/helper_test.go
index 58ea791..837c5ab 100644
--- a/internal/utils/helper.go
+++ b/internal/utils/helper_test.go
@@ -17,10 +17,21 @@ limitations under the License.
package utils
-func GetAddressByBytes(data []byte) string {
- return "127.0.0.1"
-}
+import (
+ "bytes"
+ "compress/zlib"
+ "testing"
+)
+
+func TestUnCompress(t *testing.T) {
+ var b bytes.Buffer
+ var oriStr string = "hello, go"
+ zr := zlib.NewWriter(&b)
+ zr.Write([]byte(oriStr))
+ zr.Close()
-func UnCompress(data []byte) []byte {
- return data
+ retBytes := UnCompress(b.Bytes())
+ if string(retBytes) != oriStr {
+ t.Errorf("UnCompress was incorrect, got %s, want: %s .", retBytes, []byte(oriStr))
+ }
}