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/10 04:17:22 UTC

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

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 22776e5  [INLONG-1781]Fix bug in parsing attributes of tdmsg v4 in Go SDK (#1782)
22776e5 is described below

commit 22776e50dab6a55b935c16c2f45cc0dc067105f4
Author: Zijie Lu <ws...@gmail.com>
AuthorDate: Wed Nov 10 12:17:15 2021 +0800

    [INLONG-1781]Fix bug in parsing attributes of tdmsg v4 in Go SDK (#1782)
    
    Signed-off-by: Zijie Lu <ws...@gmail.com>
---
 inlong-tubemq/tubemq-client-twins/tubemq-client-go/tdmsg/bin_msg.go | 2 +-
 inlong-tubemq/tubemq-client-twins/tubemq-client-go/tdmsg/td_msg.go  | 2 +-
 .../tubemq-client-twins/tubemq-client-go/tdmsg/td_msg_test.go       | 6 +++++-
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/inlong-tubemq/tubemq-client-twins/tubemq-client-go/tdmsg/bin_msg.go b/inlong-tubemq/tubemq-client-twins/tubemq-client-go/tdmsg/bin_msg.go
index 8afdb58..94e571d 100644
--- a/inlong-tubemq/tubemq-client-twins/tubemq-client-go/tdmsg/bin_msg.go
+++ b/inlong-tubemq/tubemq-client-twins/tubemq-client-go/tdmsg/bin_msg.go
@@ -90,7 +90,7 @@ func newBinMsg(data []byte) (*binMsg, error) {
 	}
 	dateTime := binary.BigEndian.Uint32(data[binMsgDateTimeOffset : binMsgDateTimeOffset+4])
 	rem -= 4
-	bm.dateTime = uint64(dateTime * 1000)
+	bm.dateTime = uint64(dateTime) * 1000
 
 	if rem < 2 {
 		return nil, errs.New(errs.RetTDMsgParseFailure, "parse message error: no enough data length for data v4 cnt parameter")
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 1e1fdae..cfd61b4 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
@@ -121,7 +121,7 @@ func (m *TubeMQTDMsg) parseBinMsg(data []byte) error {
 
 	var commonAttrMap map[string]string
 	if bm.attrLen > 0 {
-		attrLenPos := binMsgBodyOffset + bm.bodyLen
+		attrLenPos := binMsgBodyOffset + bm.bodyLen + binMsgAttrLenSize
 		commonAttr := data[attrLenPos : attrLenPos+uint32(bm.attrLen)]
 		commonAttrMap = util.SplitToMap(string(commonAttr), "&", "=")
 		if len(commonAttrMap) == 0 {
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
index 75e9888..936df5b 100644
--- 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
@@ -25,6 +25,10 @@ import (
 
 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)
+	tm, err := New(b)
 	assert.Nil(t, err)
+	assert.Equal(t, uint64(1636438935000), tm.CreateTime)
+	assert.Equal(t, int32(4), tm.Version)
+	assert.Equal(t, uint32(1), tm.MsgCount)
+	assert.Equal(t, false, tm.IsNumBid)
 }