Conversation
Reviewer's GuideThis PR introduces a LengthFormat abstraction for configurable length-prefixed framing, refactors LengthPrefixedProcessor to accept and use custom prefix formats, updates the application default, expands tests for different endian and size prefixes, and cleans up related documentation. Class diagram for LengthFormat and EndiannessclassDiagram
class Endianness {
<<enum>>
+Big
+Little
}
class LengthFormat {
+usize bytes
+Endianness endianness
+new(bytes: usize, endianness: Endianness)
+u16_be()
+u16_le()
+u32_be()
+u32_le()
+read_len(bytes: &[u8]) io::Result<usize>
+write_len(len: usize, dst: &mut BytesMut) io::Result<()>
}
LengthFormat --> Endianness
Class diagram for updated LengthPrefixedProcessorclassDiagram
class LengthPrefixedProcessor {
+LengthFormat format
+new(format: LengthFormat)
+decode(src: &mut BytesMut) -> Result<Option<Vec<u8>>, io::Error>
+encode(frame: &Vec<u8>, dst: &mut BytesMut) -> Result<(), io::Error>
}
LengthPrefixedProcessor --> LengthFormat
Class diagram for FrameProcessor trait and implementationclassDiagram
class FrameProcessor {
<<trait>>
+type Frame
+type Error
+decode(&self, src: &mut BytesMut) -> Result<Option<Self::Frame>, Self::Error>
+encode(&self, frame: &Self::Frame, dst: &mut BytesMut) -> Result<(), Self::Error>
}
LengthPrefixedProcessor ..|> FrameProcessor
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe changes introduce a configurable length prefix format for frame processing, replacing the previously hardcoded 4-byte big-endian prefix. This is achieved by adding new types for endianness and length format, updating the frame processor to accept these formats, and extending tests to cover various length prefix configurations. Documentation was also reformatted for clarity. Changes
Sequence Diagram(s)sequenceDiagram
participant App
participant LengthPrefixedProcessor
participant LengthFormat
App->>LengthPrefixedProcessor: new(LengthFormat)
App->>LengthPrefixedProcessor: encode(frame)
LengthPrefixedProcessor->>LengthFormat: write_len(frame.len(), buffer)
LengthPrefixedProcessor-->>App: buffer with length prefix + frame
App->>LengthPrefixedProcessor: decode(buffer)
LengthPrefixedProcessor->>LengthFormat: read_len(buffer)
LengthPrefixedProcessor-->>App: frame (if enough bytes)
Possibly related PRs
Poem
✨ Finishing Touches🧪 Generate Unit Tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Gates Failed
Prevent hotspot decline
(1 hotspot with Code Duplication)
Enforce advisory code health rules
(1 file with Code Duplication)
Gates Passed
4 Quality Gates Passed
See analysis details in CodeScene
Reason for failure
| Prevent hotspot decline | Violations | Code Health Impact | |
|---|---|---|---|
| response.rs | 1 rule in this hotspot | 10.00 → 9.39 | Suppress |
| Enforce advisory code health rules | Violations | Code Health Impact | |
|---|---|---|---|
| response.rs | 1 advisory rule | 10.00 → 9.39 | Suppress |
Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.
There was a problem hiding this comment.
Hey @leynos - I've reviewed your changes and found some issues that need to be addressed.
- Consider refactoring the almost identical match arms in
read_len/write_len(e.g. via a helper or using a byte-order utility) to reduce duplication and make future updates easier. - This PR bundles a lot of unrelated markdown formatting changes alongside the framing feature—splitting the docs/format tweaks into a separate commit or PR will keep the framing changes focused.
- It would be good to add a test for unsupported prefix sizes (e.g. 3-byte prefixes) to verify that the error paths in
read_len/write_lenare triggered correctly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider refactoring the almost identical match arms in `read_len`/`write_len` (e.g. via a helper or using a byte-order utility) to reduce duplication and make future updates easier.
- This PR bundles a lot of unrelated markdown formatting changes alongside the framing feature—splitting the docs/format tweaks into a separate commit or PR will keep the framing changes focused.
- It would be good to add a test for unsupported prefix sizes (e.g. 3-byte prefixes) to verify that the error paths in `read_len`/`write_len` are triggered correctly.
## Individual Comments
### Comment 1
<location> `src/frame.rs:48` </location>
<code_context>
+ fn read_len(&self, bytes: &[u8]) -> io::Result<usize> {
</code_context>
<issue_to_address>
Potential for panics if 'bytes' slice is too short for the specified length prefix.
Validate that 'bytes' has at least 'self.bytes' elements before accessing, and return an error if it's too short.
</issue_to_address>
### Comment 2
<location> `src/app.rs:155` </location>
<code_context>
services: Vec::new(),
middleware: Vec::new(),
- frame_processor: Box::new(LengthPrefixedProcessor),
+ frame_processor: Box::new(LengthPrefixedProcessor::new(LengthFormat::default())),
serializer: S::default(),
app_data: HashMap::new(),
</code_context>
<issue_to_address>
Remove redundant call to LengthFormat::default() as LengthPrefixedProcessor::default() already uses it.
Since LengthPrefixedProcessor::default() already constructs with LengthFormat::default(), you can simply use Box::new(LengthPrefixedProcessor::default()) for clarity and to avoid redundancy.
</issue_to_address>
### Comment 3
<location> `src/frame.rs:6` </location>
<code_context>
use std::io;
</code_context>
<issue_to_address>
The module is missing a containing item comment (`//!`).
Please add a module-level doc comment at the top of the file using `//!` to describe the purpose of this module, as required by the review instructions.
</issue_to_address>
### Comment 4
<location> `docs/roadmap.md:91` </location>
<code_context>
- 866-899) and introduce a `Next` helper to build the asynchronous call
- chain. Trait definitions live in
- [`src/middleware.rs`](../src/middleware.rs#L71-L84).
+ 866-899) and introduce a `Next` helper to build the asynchronous call chain.
+ Trait definitions live in
+ [`src/middleware.rs`](../src/middleware.rs#L71-L84).
</code_context>
<issue_to_address>
Bullet point line exceeds 80 columns and is not wrapped as required.
Please wrap this bullet point so that no line exceeds 80 columns, as per the documentation guidelines.
</issue_to_address>
### Comment 5
<location> `docs/roadmap.md:92` </location>
<code_context>
- chain. Trait definitions live in
- [`src/middleware.rs`](../src/middleware.rs#L71-L84).
+ 866-899) and introduce a `Next` helper to build the asynchronous call chain.
+ Trait definitions live in
+ [`src/middleware.rs`](../src/middleware.rs#L71-L84).
+
</code_context>
<issue_to_address>
Bullet point line is not wrapped to 80 columns, which is required for documentation.
Ensure that all bullet points and paragraphs are wrapped to 80 columns for consistency and readability.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…prefixedprocessor` Docstrings generation was requested by @leynos. * #87 (comment) The following files were modified: * `src/app.rs` * `src/frame.rs` * `tests/response.rs`
|
Note Generated docstrings for this pull request at #89 |
…prefixedprocessor` (#89) * 📝 Add docstrings to `codex/define-endianness-enum-and-refactor-lengthprefixedprocessor` Docstrings generation was requested by @leynos. * #87 (comment) The following files were modified: * `src/app.rs` * `src/frame.rs` * `tests/response.rs` * Move attributes below doc comments (#90) --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Leynos <leynos@troubledskies.net>
There was a problem hiding this comment.
Gates Failed
Prevent hotspot decline
(1 hotspot with Code Duplication)
Enforce advisory code health rules
(1 file with Code Duplication)
Gates Passed
4 Quality Gates Passed
See analysis details in CodeScene
Reason for failure
| Prevent hotspot decline | Violations | Code Health Impact | |
|---|---|---|---|
| response.rs | 1 rule in this hotspot | 10.00 → 9.39 | Suppress |
| Enforce advisory code health rules | Violations | Code Health Impact | |
|---|---|---|---|
| response.rs | 1 advisory rule | 10.00 → 9.39 | Suppress |
Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.
There was a problem hiding this comment.
Gates Failed
Prevent hotspot decline
(1 hotspot with Code Duplication)
Enforce advisory code health rules
(1 file with Code Duplication)
Gates Passed
4 Quality Gates Passed
See analysis details in CodeScene
Reason for failure
| Prevent hotspot decline | Violations | Code Health Impact | |
|---|---|---|---|
| response.rs | 1 rule in this hotspot | 10.00 → 9.39 | Suppress |
| Enforce advisory code health rules | Violations | Code Health Impact | |
|---|---|---|---|
| response.rs | 1 advisory rule | 10.00 → 9.39 | Suppress |
Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.
There was a problem hiding this comment.
Gates Failed
Prevent hotspot decline
(1 hotspot with Code Duplication)
Enforce advisory code health rules
(1 file with Code Duplication)
Gates Passed
4 Quality Gates Passed
See analysis details in CodeScene
Reason for failure
| Prevent hotspot decline | Violations | Code Health Impact | |
|---|---|---|---|
| response.rs | 1 rule in this hotspot | 10.00 → 9.39 | Suppress |
| Enforce advisory code health rules | Violations | Code Health Impact | |
|---|---|---|---|
| response.rs | 1 advisory rule | 10.00 → 9.39 | Suppress |
Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.
Summary
Testing
make fmtmake lintmake testmarkdownlint README.md docs/*.mdhttps://chatgpt.com/codex/tasks/task_e_6855703c05fc8322875a99e9eaf065e1
Summary by Sourcery
Add support for configurable length-prefixed framing by abstracting prefix size and endianness into a LengthFormat, update the processor and app defaults accordingly, and provide documentation and tests for custom formats.
New Features:
Enhancements:
Documentation:
Tests:
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Tests