Copilot commented on code in PR #10535:
URL: https://github.com/apache/rocketmq/pull/10535#discussion_r3447778765
##########
remoting/src/main/java/org/apache/rocketmq/remoting/protocol/header/SendMessageRequestHeader.java:
##########
@@ -183,22 +191,140 @@ public void setBatch(Boolean batch) {
}
public static SendMessageRequestHeader parseRequestHeader(RemotingCommand
request) throws RemotingCommandException {
- SendMessageRequestHeaderV2 requestHeaderV2 = null;
- SendMessageRequestHeader requestHeader = null;
- switch (request.getCode()) {
- case RequestCode.SEND_BATCH_MESSAGE:
- case RequestCode.SEND_MESSAGE_V2:
- requestHeaderV2 =
request.decodeCommandCustomHeader(SendMessageRequestHeaderV2.class);
- case RequestCode.SEND_MESSAGE:
- if (null == requestHeaderV2) {
- requestHeader =
request.decodeCommandCustomHeader(SendMessageRequestHeader.class);
- } else {
- requestHeader =
SendMessageRequestHeaderV2.createSendMessageRequestHeaderV1(requestHeaderV2);
- }
- default:
- break;
- }
- return requestHeader;
+ return
request.decodeCommandCustomHeader(SendMessageRequestHeader.class);
+ }
+
+ @Override
+ public void encode(ByteBuf out) {
+ writeIfNotNull(out, "a", producerGroup);
+ writeIfNotNull(out, "b", topic);
+ writeIfNotNull(out, "c", defaultTopic);
+ writeIfNotNull(out, "d", defaultTopicQueueNums);
+ writeIfNotNull(out, "e", queueId);
+ writeIfNotNull(out, "f", sysFlag);
+ writeIfNotNull(out, "g", bornTimestamp);
+ writeIfNotNull(out, "h", flag);
+ writeIfNotNull(out, "i", properties);
+ writeIfNotNull(out, "j", reconsumeTimes);
+ writeIfNotNull(out, "k", unitMode);
+ writeIfNotNull(out, "l", maxReconsumeTimes);
+ writeIfNotNull(out, "m", batch);
+ writeIfNotNull(out, "n", getBname());
+ }
+
+ @Override
+ public void decode(HashMap<String, String> fields) throws
RemotingCommandException {
+ String str = fields.get("a");
+ if (str == null) {
+ str = getAndCheckNotNull(fields, "producerGroup");
+ }
+ if (str != null) {
+ this.producerGroup = str;
+ }
+
+ str = fields.get("b");
+ if (str == null) {
+ str = getAndCheckNotNull(fields, "topic");
+ }
+ if (str != null) {
+ this.topic = str;
+ }
+
+ str = fields.get("c");
+ if (str == null) {
+ str = getAndCheckNotNull(fields, "defaultTopic");
+ }
+ if (str != null) {
+ this.defaultTopic = str;
+ }
+
+ str = fields.get("d");
+ if (str == null) {
+ str = getAndCheckNotNull(fields, "defaultTopicQueueNums");
+ }
+ if (str != null) {
+ this.defaultTopicQueueNums = Integer.parseInt(str);
+ }
+
+ str = fields.get("e");
+ if (str == null) {
+ str = getAndCheckNotNull(fields, "queueId");
+ }
+ if (str != null) {
+ this.queueId = Integer.parseInt(str);
+ }
+
+ str = fields.get("f");
+ if (str == null) {
+ str = getAndCheckNotNull(fields, "sysFlag");
+ }
+ if (str != null) {
+ this.sysFlag = Integer.parseInt(str);
+ }
+
+ str = fields.get("g");
+ if (str == null) {
+ str = getAndCheckNotNull(fields, "bornTimestamp");
+ }
+ if (str != null) {
+ this.bornTimestamp = Long.parseLong(str);
+ }
+
+ str = fields.get("h");
+ if (str == null) {
+ str = getAndCheckNotNull(fields, "flag");
+ }
+ if (str != null) {
+ this.flag = Integer.parseInt(str);
+ }
+
+ str = fields.get("i");
+ if (str == null) {
+ str = fields.get("properties");
+ }
+ if (str != null) {
+ this.properties = str;
+ }
+
+ str = fields.get("j");
+ if (str == null) {
+ str = fields.get("reconsumeTimes");
+ }
+ if (str != null) {
+ this.reconsumeTimes = Integer.parseInt(str);
+ }
+
+ str = fields.get("k");
+ if (str == null) {
+ str = fields.get("unitMode");
+ }
+ if (str != null) {
+ this.unitMode = Boolean.parseBoolean(str);
+ }
+
+ str = fields.get("l");
+ if (str == null) {
+ str = fields.get("maxReconsumeTimes");
+ }
+ if (str != null) {
+ this.maxReconsumeTimes = Integer.parseInt(str);
+ }
+
+ str = fields.get("m");
+ if (str == null) {
+ str = fields.get("batch");
+ }
+ if (str != null) {
+ this.batch = Boolean.parseBoolean(str);
+ }
+
+ str = fields.get("n");
+ if (str == null) {
+ str = fields.get("brokerName");
+ }
+ if (str != null) {
+ this.setBrokerName(str);
+ }
Review Comment:
`decode()` falls back to `fields.get("brokerName")`, but the inherited field
name used in extFields for v1 requests is `bname` (from `RpcRequestHeader`).
With current code, v1 requests that include broker name under `bname` won't
populate the header's broker name.
##########
remoting/src/main/java/org/apache/rocketmq/remoting/protocol/header/SendMessageRequestHeader.java:
##########
@@ -183,22 +191,140 @@ public void setBatch(Boolean batch) {
}
public static SendMessageRequestHeader parseRequestHeader(RemotingCommand
request) throws RemotingCommandException {
- SendMessageRequestHeaderV2 requestHeaderV2 = null;
- SendMessageRequestHeader requestHeader = null;
- switch (request.getCode()) {
- case RequestCode.SEND_BATCH_MESSAGE:
- case RequestCode.SEND_MESSAGE_V2:
- requestHeaderV2 =
request.decodeCommandCustomHeader(SendMessageRequestHeaderV2.class);
- case RequestCode.SEND_MESSAGE:
- if (null == requestHeaderV2) {
- requestHeader =
request.decodeCommandCustomHeader(SendMessageRequestHeader.class);
- } else {
- requestHeader =
SendMessageRequestHeaderV2.createSendMessageRequestHeaderV1(requestHeaderV2);
- }
- default:
- break;
- }
- return requestHeader;
+ return
request.decodeCommandCustomHeader(SendMessageRequestHeader.class);
+ }
+
+ @Override
+ public void encode(ByteBuf out) {
+ writeIfNotNull(out, "a", producerGroup);
+ writeIfNotNull(out, "b", topic);
+ writeIfNotNull(out, "c", defaultTopic);
+ writeIfNotNull(out, "d", defaultTopicQueueNums);
+ writeIfNotNull(out, "e", queueId);
+ writeIfNotNull(out, "f", sysFlag);
+ writeIfNotNull(out, "g", bornTimestamp);
+ writeIfNotNull(out, "h", flag);
+ writeIfNotNull(out, "i", properties);
+ writeIfNotNull(out, "j", reconsumeTimes);
+ writeIfNotNull(out, "k", unitMode);
+ writeIfNotNull(out, "l", maxReconsumeTimes);
+ writeIfNotNull(out, "m", batch);
+ writeIfNotNull(out, "n", getBname());
+ }
Review Comment:
`encode()` is writing short keys ("a".."n") for `RequestCode.SEND_MESSAGE`.
This changes the on-wire extFields keys (e.g., topic becomes "b" instead of
"topic", brokerName becomes "n" instead of "bname") and will break components
that read extFields directly (e.g., authorization builder expects
"topic"/"producerGroup", proxy expects "bname") and also breaks backward
compatibility with older brokers/clients that decode by field name.
##########
remoting/src/main/java/org/apache/rocketmq/remoting/protocol/header/SendMessageRequestHeaderV2.java:
##########
@@ -20,6 +20,7 @@
import com.google.common.base.MoreObjects;
import io.netty.buffer.ByteBuf;
import java.util.HashMap;
+import java.util.Map;
Review Comment:
`java.util.Map` is imported but never used in this class; this can fail
style/unused-import checks.
##########
remoting/src/main/java/org/apache/rocketmq/remoting/protocol/header/SendMessageResponseHeader.java:
##########
@@ -22,6 +22,7 @@
import io.netty.buffer.ByteBuf;
import java.util.HashMap;
+import java.util.HashMap;
Review Comment:
Duplicate `HashMap` import; this can fail style/unused-import checks and
adds noise.
##########
remoting/src/main/java/org/apache/rocketmq/remoting/protocol/header/SendMessageRequestHeader.java:
##########
@@ -21,19 +21,23 @@
package org.apache.rocketmq.remoting.protocol.header;
import com.google.common.base.MoreObjects;
+import io.netty.buffer.ByteBuf;
+import java.util.HashMap;
+import java.util.HashMap;
Review Comment:
Duplicate `HashMap` import; this can fail style/unused-import checks and
adds noise.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]