{{ message }}
codec: fix broken length_delimited builder doc examples - #8350
Merged
Darksonn merged 1 commit intoAug 9, 2026
Merged
Conversation
The Builder::new, new_codec, and new_read doc examples combined length_adjustment(0) with num_skip(0). This leaves the length header bytes in the buffer without accounting for them, so decoding returns a frame that includes the raw header at the front and is short at the back, corrupting the following frame. Drop num_skip(0) so the default (skip the header) behavior applies, and turn all three examples into executable doctests that perform a real encode/decode round-trip and assert on the payload, so this class of bug is caught automatically going forward. Fixes: tokio-rs#8348
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The
Builder::new,new_codec, andnew_readdoc examples combinelength_adjustment(0)withnum_skip(0). This leaves the length header bytes in the buffer without accounting for them, so decoding returns a frame that includes the raw header at the front and is short at the back, corrupting the following frame.Motivation
Copying these examples as written produces a
LengthDelimitedCodecthat silently corrupts every frame after the first, since the length header is never skipped but the byte count returned bydecodeisn't adjusted to account for it.Solution
Drop
num_skip(0)so the default (skip the header) behavior applies, and turn all three examples into executable doctests that perform a real encode/decode round-trip and assert on the payload, so this class of bug is caught automatically going forward.new_writewas already correct and is unchanged.Fixes #8348
Note: aware of #8349 which addresses the same issue — opening this as an independent fix.