-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
LengthDelimitedCodec example not correct in Document #4184
Comments
@Darksonn I can take a look at this one this week. |
The results of my tests look as if they are correct. My code: use bytes::Bytes;
use futures::SinkExt;
use tokio::fs::File;
use tokio::io::{AsyncRead, AsyncWrite};
use tokio_util::codec::{Framed, LengthDelimitedCodec};
async fn write_frame<T>(io: T) -> Result<(), Box<dyn std::error::Error>>
where
T: AsyncRead + AsyncWrite + Unpin,
{
let codec = LengthDelimitedCodec::builder()
.length_field_offset(0) // default value
.length_field_length(2)
.length_adjustment(-2) // size of head
.num_skip(0) // Do not strip frame header
.new_codec();
let mut transport = Framed::new(io, codec);
let frame = Bytes::from("hello world");
print!("{:?}", frame);
transport.send(frame).await?;
Ok(())
}
#[tokio::main]
async fn main() {
let file = File::create("foo.txt").await.unwrap();
write_frame(file).await.unwrap();
} |
Is this issue still open? I can't figure out what the problem is with the original issue. The docs appears to be correct, curious what the issue was. |
@matthiasdebernardini Not sure. Has the file changed since this issue? |
yes it has, The example output from @hi-rustin outputs I'm just going through these "good first issues" so I can learn the project better. |
If this issue has been fixed, then we should close it. |
Sorry for response later, I close it now. |
It seems that there is no method Update: it is imperative to have import |
The |
tokio-util version
0.6.8.
Platform
Darwin MacBook-Pro.local 19.6.0 Darwin Kernel Version 19.6.0: Thu Oct 29 22:56:45 PDT 2020; root:xnu-6153.141.2.2~1/RELEASE_X86_64 x86_64
Description
I find some examples in LengthDelimitedCodec seems not correct.
First
:tokio/tokio-util/src/codec/length_delimited.rs
Lines 76 to 101 in 44e9013
I run this example, the decoded result is
\x00 \x0B Hello wor
, which in the example should\x00\x0B Hello world
, the issue is that the length does not contain the length of the header, or we can just set length_adjustment.Second
:tokio/tokio-util/src/codec/length_delimited.rs
Lines 141 to 168 in 44e9013
My decoded result is
\x00\x0D Hello wor
, which in the example is\x00\x0D Hello world
.Third
:tokio/tokio-util/src/codec/length_delimited.rs
Lines 176 to 206 in 44e9013
My decoded result is
\x00\x00\x0B\xCA\xFE Hello wo
, which in document is\x00\x00\x0B \xCA\xFE Hello world
.The text was updated successfully, but these errors were encountered: