You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by go...@apache.org on 2021/11/09 11:03:13 UTC

[incubator-inlong] branch master updated: [INLONG-1777]Fix bug in parsing tdmsg v4 of Go SDK (#1778)

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

gosonzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-inlong.git


The following commit(s) were added to refs/heads/master by this push:
     new 0cf7495  [INLONG-1777]Fix bug in parsing tdmsg v4 of Go SDK (#1778)
0cf7495 is described below

commit 0cf749550e675d0d4632cb5772859cf1106e1302
Author: Zijie Lu <ws...@gmail.com>
AuthorDate: Tue Nov 9 19:03:08 2021 +0800

    [INLONG-1777]Fix bug in parsing tdmsg v4 of Go SDK (#1778)
    
    Signed-off-by: Zijie Lu <ws...@gmail.com>
---
 .../tubemq-client-go/tdmsg/td_msg.go               |  4 +--
 .../tubemq-client-go/tdmsg/td_msg_test.go          | 30 ++++++++++++++++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/inlong-tubemq/tubemq-client-twins/tubemq-client-go/tdmsg/td_msg.go b/inlong-tubemq/tubemq-client-twins/tubemq-client-go/tdmsg/td_msg.go
index da56466..1e1fdae 100644
--- a/inlong-tubemq/tubemq-client-twins/tubemq-client-go/tdmsg/td_msg.go
+++ b/inlong-tubemq/tubemq-client-twins/tubemq-client-go/tdmsg/td_msg.go
@@ -133,7 +133,7 @@ func (m *TubeMQTDMsg) parseBinMsg(data []byte) error {
 	body := bm.body
 	if (bm.msgType&0xE0)>>5 == 1 {
 		var err error
-		body, err = getDecodedData(data[1:], int32(v4))
+		body, err = getDecodedData(body, int32(v4))
 		if err != nil {
 			return err
 		}
@@ -367,7 +367,7 @@ func getDecodedData(data []byte, ver int32) ([]byte, error) {
 	decodedData := make([]byte, 0, decodedLen)
 	decodedData, err = snappy.Decode(decodedData, data)
 	if err != nil {
-		return nil, errs.New(errs.RetTDMsgParseFailure, fmt.Sprintf("parse message error:  snappy uncompressed v%d's compress's length failure", ver))
+		return nil, errs.New(errs.RetTDMsgParseFailure, fmt.Sprintf("parse message error:  snappy uncompressed v%d's compress's data failure", ver))
 	}
 	return decodedData, nil
 }
diff --git a/inlong-tubemq/tubemq-client-twins/tubemq-client-go/tdmsg/td_msg_test.go b/inlong-tubemq/tubemq-client-twins/tubemq-client-go/tdmsg/td_msg_test.go
new file mode 100644
index 0000000..75e9888
--- /dev/null
+++ b/inlong-tubemq/tubemq-client-twins/tubemq-client-go/tdmsg/td_msg_test.go
@@ -0,0 +1,30 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package tdmsg
+
+import (
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestTDMsgV4(t *testing.T) {
+	b := []byte{15, 4, 0, 0, 2, 129, 39, 0, 0, 0, 0, 0, 4, 97, 138, 19, 151, 0, 1, 0, 6, 168, 171, 0, 0, 1, 254, 180, 5, 168, 0, 0, 2, 176, 106, 111, 115, 105, 101, 106, 121, 99, 104, 101, 110, 9, 108, 105, 103, 104, 116, 9, 110, 117, 108, 108, 9, 83, 69, 76, 69, 67, 84, 32, 42, 32, 102, 114, 111, 109, 32, 40, 32, 13, 16, 64, 112, 114, 111, 100, 117, 99, 116, 95, 105, 100, 44, 99, 111, 110, 116, 101, 110, 5, 11, 0, 32, 13, 1, 104, 99, 111, 117, 110, 116, 40, 68, 73, 83, 84, 73, 78, 67, 84,  [...]
+	_, err := New(b)
+	assert.Nil(t, err)
+}