[ISSUE #782]🚀PullMessageResponseHeader implement FastCodesHeader🚀#783
[ISSUE #782]🚀PullMessageResponseHeader implement FastCodesHeader🚀#783
Conversation
WalkthroughThe recent changes introduce improvements and bug fixes to the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant PullMessageResponseHeader
participant HashMap
Client->>PullMessageResponseHeader: Create instance
PullMessageResponseHeader->>HashMap: Convert to map
HashMap-->>PullMessageResponseHeader: Return map data
PullMessageResponseHeader->>Client: Return encoded data
Client->>PullMessageResponseHeader: Decode data from map
PullMessageResponseHeader->>PullMessageResponseHeader: Populate fields
PullMessageResponseHeader-->>Client: Return populated instance
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
|
🚀Thanks for your contribution🎉. CodeRabbit(AI) will review your code first🔥 |
There was a problem hiding this comment.
Actionable comments posted: 2
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files selected for processing (3)
- rocketmq-remoting/src/error.rs (1 hunks)
- rocketmq-remoting/src/protocol/command_custom_header.rs (1 hunks)
- rocketmq-remoting/src/protocol/header/pull_message_response_header.rs (3 hunks)
Files skipped from review due to trivial changes (1)
- rocketmq-remoting/src/error.rs
Additional comments not posted (4)
rocketmq-remoting/src/protocol/command_custom_header.rs (1)
55-55: LGTM! The logical error is fixed.The function now correctly writes the
valueparameter instead of thekeyparameter.rocketmq-remoting/src/protocol/header/pull_message_response_header.rs (3)
41-48: LGTM! The added constants improve readability.The constants for various fields in the
PullMessageResponseHeaderstruct enhance code readability and maintainability.
Line range hint
80-141:
LGTM! The implementation ofCommandCustomHeaderis correct.The methods
to_map,encode_fast,decode_fast, andsupport_fast_codecare implemented correctly.
170-274: LGTM! The unit tests are comprehensive.The unit tests for
from_map,to_map,encode_fast, anddecode_fastmethods cover various scenarios and ensure the correctness of the implementation.
| impl CommandCustomHeader for PullMessageResponseHeader { | ||
| fn to_map(&self) -> Option<HashMap<String, String>> { | ||
| let mut map = HashMap::new(); | ||
| if let Some(value) = self.suggest_which_broker_id { | ||
| map.insert(Self::SUGGEST_WHICH_BROKER_ID.to_string(), value.to_string()); | ||
| } | ||
| if let Some(value) = self.next_begin_offset { | ||
| map.insert(Self::NEXT_BEGIN_OFFSET.to_string(), value.to_string()); | ||
| } | ||
| if let Some(value) = self.min_offset { | ||
| map.insert(Self::MIN_OFFSET.to_string(), value.to_string()); | ||
| } | ||
| if let Some(value) = self.max_offset { | ||
| map.insert(Self::MAX_OFFSET.to_string(), value.to_string()); | ||
| } | ||
| if let Some(value) = self.offset_delta { | ||
| map.insert(Self::OFFSET_DELTA.to_string(), value.to_string()); | ||
| } | ||
| if let Some(value) = self.topic_sys_flag { | ||
| map.insert(Self::TOPIC_SYS_FLAG.to_string(), value.to_string()); | ||
| } | ||
| if let Some(value) = self.group_sys_flag { | ||
| map.insert(Self::GROUP_SYS_FLAG.to_string(), value.to_string()); | ||
| } | ||
| if let Some(value) = self.forbidden_type { | ||
| map.insert(Self::FORBIDDEN_TYPE.to_string(), value.to_string()); | ||
| } | ||
| Some(map) | ||
| } |
There was a problem hiding this comment.
Handle potential parsing errors in decode_fast and from methods.
The unwrap calls in decode_fast and from methods can cause the program to panic if parsing fails. Consider handling these errors more gracefully.
- self.suggest_which_broker_id = Some(offset_delta.parse().unwrap());
+ self.suggest_which_broker_id = offset_delta.parse().ok();
- suggest_which_broker_id: suggest_which_broker_id.map(|v| v.parse().unwrap()),
+ suggest_which_broker_id: suggest_which_broker_id.and_then(|v| v.parse().ok()),Committable suggestion was skipped due to low confidence.
| impl FromMap for PullMessageResponseHeader { | ||
| type Target = Self; | ||
|
|
||
| fn from(map: &HashMap<String, String>) -> Option<Self::Target> { | ||
| let suggest_which_broker_id = map.get(PullMessageResponseHeader::SUGGEST_WHICH_BROKER_ID); | ||
| let next_begin_offset = map.get(PullMessageResponseHeader::NEXT_BEGIN_OFFSET); | ||
| let min_offset = map.get(PullMessageResponseHeader::MIN_OFFSET); | ||
| let max_offset = map.get(PullMessageResponseHeader::MAX_OFFSET); | ||
| let offset_delta = map.get(PullMessageResponseHeader::OFFSET_DELTA); | ||
| let topic_sys_flag = map.get(PullMessageResponseHeader::TOPIC_SYS_FLAG); | ||
| let group_sys_flag = map.get(PullMessageResponseHeader::GROUP_SYS_FLAG); | ||
| let forbidden_type = map.get(PullMessageResponseHeader::FORBIDDEN_TYPE); | ||
|
|
||
| Some(PullMessageResponseHeader { | ||
| suggest_which_broker_id: suggest_which_broker_id.map(|v| v.parse().unwrap()), | ||
| next_begin_offset: next_begin_offset.map(|v| v.parse().unwrap()), | ||
| min_offset: min_offset.map(|v| v.parse().unwrap()), | ||
| max_offset: max_offset.map(|v| v.parse().unwrap()), | ||
| offset_delta: offset_delta.map(|v| v.parse().unwrap()), | ||
| topic_sys_flag: topic_sys_flag.map(|v| v.parse().unwrap()), | ||
| group_sys_flag: group_sys_flag.map(|v| v.parse().unwrap()), | ||
| forbidden_type: forbidden_type.map(|v| v.parse().unwrap()), | ||
| }) | ||
| } |
There was a problem hiding this comment.
Handle potential parsing errors in the from method.
The unwrap calls in the from method can cause the program to panic if parsing fails. Consider handling these errors more gracefully.
- suggest_which_broker_id: suggest_which_broker_id.map(|v| v.parse().unwrap()),
+ suggest_which_broker_id: suggest_which_broker_id.and_then(|v| v.parse().ok()),Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| impl FromMap for PullMessageResponseHeader { | |
| type Target = Self; | |
| fn from(map: &HashMap<String, String>) -> Option<Self::Target> { | |
| let suggest_which_broker_id = map.get(PullMessageResponseHeader::SUGGEST_WHICH_BROKER_ID); | |
| let next_begin_offset = map.get(PullMessageResponseHeader::NEXT_BEGIN_OFFSET); | |
| let min_offset = map.get(PullMessageResponseHeader::MIN_OFFSET); | |
| let max_offset = map.get(PullMessageResponseHeader::MAX_OFFSET); | |
| let offset_delta = map.get(PullMessageResponseHeader::OFFSET_DELTA); | |
| let topic_sys_flag = map.get(PullMessageResponseHeader::TOPIC_SYS_FLAG); | |
| let group_sys_flag = map.get(PullMessageResponseHeader::GROUP_SYS_FLAG); | |
| let forbidden_type = map.get(PullMessageResponseHeader::FORBIDDEN_TYPE); | |
| Some(PullMessageResponseHeader { | |
| suggest_which_broker_id: suggest_which_broker_id.map(|v| v.parse().unwrap()), | |
| next_begin_offset: next_begin_offset.map(|v| v.parse().unwrap()), | |
| min_offset: min_offset.map(|v| v.parse().unwrap()), | |
| max_offset: max_offset.map(|v| v.parse().unwrap()), | |
| offset_delta: offset_delta.map(|v| v.parse().unwrap()), | |
| topic_sys_flag: topic_sys_flag.map(|v| v.parse().unwrap()), | |
| group_sys_flag: group_sys_flag.map(|v| v.parse().unwrap()), | |
| forbidden_type: forbidden_type.map(|v| v.parse().unwrap()), | |
| }) | |
| } | |
| impl FromMap for PullMessageResponseHeader { | |
| type Target = Self; | |
| fn from(map: &HashMap<String, String>) -> Option<Self::Target> { | |
| let suggest_which_broker_id = map.get(PullMessageResponseHeader::SUGGEST_WHICH_BROKER_ID); | |
| let next_begin_offset = map.get(PullMessageResponseHeader::NEXT_BEGIN_OFFSET); | |
| let min_offset = map.get(PullMessageResponseHeader::MIN_OFFSET); | |
| let max_offset = map.get(PullMessageResponseHeader::MAX_OFFSET); | |
| let offset_delta = map.get(PullMessageResponseHeader::OFFSET_DELTA); | |
| let topic_sys_flag = map.get(PullMessageResponseHeader::TOPIC_SYS_FLAG); | |
| let group_sys_flag = map.get(PullMessageResponseHeader::GROUP_SYS_FLAG); | |
| let forbidden_type = map.get(PullMessageResponseHeader::FORBIDDEN_TYPE); | |
| Some(PullMessageResponseHeader { | |
| suggest_which_broker_id: suggest_which_broker_id.and_then(|v| v.parse().ok()), | |
| next_begin_offset: next_begin_offset.map(|v| v.parse().unwrap()), | |
| min_offset: min_offset.map(|v| v.parse().unwrap()), | |
| max_offset: max_offset.map(|v| v.parse().unwrap()), | |
| offset_delta: offset_delta.map(|v| v.parse().unwrap()), | |
| topic_sys_flag: topic_sys_flag.map(|v| v.parse().unwrap()), | |
| group_sys_flag: group_sys_flag.map(|v| v.parse().unwrap()), | |
| forbidden_type: forbidden_type.map(|v| v.parse().unwrap()), | |
| }) | |
| } |
Which Issue(s) This PR Fixes(Closes)
Fixes #782
Brief Description
How Did You Test This Change?
Summary by CodeRabbit
New Features
PullMessageResponseHeaderto support mapping, encoding, and decoding functionalities.PullMessageResponseHeader.Bug Fixes
write_if_not_nullfunction to write thevalueparameter instead of thekeyparameter.Maintenance