You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2021/12/28 11:29:04 UTC

[GitHub] [rocketmq-client-go] maixiaohai commented on a change in pull request #765: [ISSUE #759] Change ResetOffsetBody response parse method to support fastjson schema

maixiaohai commented on a change in pull request #765:
URL: https://github.com/apache/rocketmq-client-go/pull/765#discussion_r775860371



##########
File path: internal/model.go
##########
@@ -295,12 +295,39 @@ type ResetOffsetBody struct {
 	OffsetTable map[primitive.MessageQueue]int64 `json:"offsetTable"`
 }
 
+// Decode note: the origin implementation for parse json is in gson format.
+// this func should support both gson and fastjson schema.
 func (resetOffsetBody *ResetOffsetBody) Decode(body []byte) {
+	validJSON := gjson.ValidBytes(body)
+
+	var offsetTable map[primitive.MessageQueue]int64
+
+	if validJSON {
+		offsetTable = parseGsonFormat(body)
+	} else {
+		offsetTable = parseFastJsonFormat(body)
+	}
+
+	resetOffsetBody.OffsetTable = offsetTable
+}
+
+func parseGsonFormat(body []byte) map[primitive.MessageQueue]int64 {
 	result := gjson.ParseBytes(body)
+
 	rlog.Debug("offset table string "+result.Get("offsetTable").String(), nil)
 
 	offsetTable := make(map[primitive.MessageQueue]int64, 0)
-	offsetTableArray := strings.Split(result.Get("offsetTable").String(), "],[")
+
+	offsetStr := result.Get("offsetTable").String()
+	if len(offsetStr) <= 2 {

Review comment:
       请教下,何时会触发这个情况




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org