-
Notifications
You must be signed in to change notification settings - Fork 144
[ISSUE #1476]♻️Refactor derive RequestHeaderCodec parse logic🔥 #1478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe changes in this pull request focus on the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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 using PR comments)
Other keywords and placeholders
Documentation and Community
|
🔊@mxsm 🚀Thanks for your contribution 🎉. CodeRabbit(AI) will review your code first 🔥 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
rocketmq-macros/src/request_header_custom.rs (2)
68-72
: LGTM! Consider adding documentation.The refactored type name determination logic is well-structured and correctly handles both Option and direct types. This change improves code organization by consolidating the type handling logic.
Consider adding a doc comment explaining the type name determination logic:
+ // Determine the underlying type name, handling both Option<T> and direct T types + // For Option<T>, extracts and returns the name of T + // For direct types, returns the type name as is let type_name = if let Some(value) = &has_option { get_type_name(*value) } else { get_type_name(&field.ty) };
Line range hint
78-107
: Consider reducing code duplication in map insertion logic.While the map insertion logic is functionally correct, there's noticeable duplication in the handling of different types. Consider extracting the common map insertion pattern into a helper function.
Here's a suggested refactor:
impl #struct_name { // Helper function to handle map insertion with proper type conversion fn insert_value<T: ToString>( map: &mut HashMap<CheetahString, CheetahString>, key: &'static str, value: &T, is_string_type: bool, ) { let value_str = if is_string_type { value.to_string() } else { value.to_string() }; map.insert( CheetahString::from_static_str(key), CheetahString::from_string(value_str), ); } }This would simplify the map insertion code to:
if let Some(ref value) = self.#field_name { Self::insert_value(&mut map, Self::#static_name, value, type_name == "String"); }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
rocketmq-macros/src/request_header_custom.rs
(2 hunks)
🔇 Additional comments (1)
rocketmq-macros/src/request_header_custom.rs (1)
Line range hint 1-236
: Verify handling of all request header types.
Let's ensure that all request header types in the codebase are properly handled by this refactored codec implementation.
✅ Verification successful
Let me gather more specific information about the field types used in these request headers.
Based on the analysis of the request headers, I can now provide a final response:
The request header codec implementation properly handles all used types
The implementation correctly handles all field types found in the request headers:
- Basic types:
i32
,i64
are handled via theparse
andto_string
methods CheetahString
has dedicated handling in bothto_map
andfrom_map
Option<T>
wrapping of these types is properly managed- All fields are correctly converted to camelCase for Java compatibility
The macro implementation in request_header_custom.rs
covers all cases found in the actual usage across the codebase, including:
- Required and optional fields
- String types (both native and CheetahString)
- Numeric types with proper parsing
- Proper error handling for missing required fields
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Find all structs that derive RequestHeaderCodec to verify compatibility
# Search for structs that derive RequestHeaderCodec
echo "Searching for RequestHeaderCodec implementations..."
rg -l "derive.*RequestHeaderCodec"
# Search for potential custom type fields that might need special handling
echo "Checking field types in request header structs..."
ast-grep --pattern 'struct $struct_name {
$$$
$field_name: $type
$$$
}'
Length of output: 1125
Script:
#!/bin/bash
# Check the actual field types in RequestHeaderCodec implementations
echo "Analyzing field types in RequestHeaderCodec structs..."
for file in $(rg -l 'derive.*RequestHeaderCodec'); do
echo "=== $file ==="
rg -A 10 'struct.*\{' "$file"
done
# Specifically check for any custom types being used
echo -e "\nChecking for custom type usage..."
ast-grep --pattern 'struct $_ {
$$$
$_: $type
$$$
}' rocketmq-remoting/src/protocol/header/**/*.rs
Length of output: 6008
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1478 +/- ##
==========================================
- Coverage 22.31% 22.31% -0.01%
==========================================
Files 450 450
Lines 58289 58288 -1
==========================================
- Hits 13007 13006 -1
Misses 45282 45282 ☔ View full report in Codecov by Sentry. |
🔊@mxsm 🚀Thanks for your contribution 🎉. CodeRabbit(AI) will review your code first 🔥 |
Which Issue(s) This PR Fixes(Closes)
Fixes #1476
Brief Description
How Did You Test This Change?
Summary by CodeRabbit
Bug Fixes
Option
types, enhancing the logic for value insertion and deserialization.Refactor
Style