wang-jiahua commented on code in PR #10469:
URL: https://github.com/apache/rocketmq/pull/10469#discussion_r3393565919
##########
common/src/main/java/org/apache/rocketmq/common/message/MessageVersion.java:
##########
@@ -71,12 +71,12 @@ public void putTopicLength(ByteBuffer buffer, int
topicLength) {
}
public static MessageVersion valueOfMagicCode(int magicCode) {
- for (MessageVersion version : MessageVersion.values()) {
- if (version.getMagicCode() == magicCode) {
- return version;
- }
+ if (magicCode == MessageDecoder.MESSAGE_MAGIC_CODE) {
Review Comment:
Done — switched to `switch` statement. Reads slightly cleaner with the
`default: throw` pattern.
##########
common/src/main/java/org/apache/rocketmq/common/message/MessageVersion.java:
##########
@@ -71,12 +71,12 @@ public void putTopicLength(ByteBuffer buffer, int
topicLength) {
}
public static MessageVersion valueOfMagicCode(int magicCode) {
- for (MessageVersion version : MessageVersion.values()) {
- if (version.getMagicCode() == magicCode) {
- return version;
- }
+ if (magicCode == MessageDecoder.MESSAGE_MAGIC_CODE) {
Review Comment:
Good suggestion! Added `MessageVersionTest` with `testValueOfMagicCode()`
that iterates all versions and asserts round-trip through
`valueOfMagicCode(getMagicCode())`. Also added a negative test for invalid
magic codes.
--
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]