mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
util: documentation example for LengthDelimitedCodec (#2339)
There is a gap in examples for Builder::num_skip() that shows how to move past unused bytes between the length and payload.
This commit is contained in:
@@ -372,6 +372,25 @@ fn read_single_multi_frame_one_packet_skip_none_adjusted() {
|
||||
assert_done!(io);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn read_single_frame_length_adjusted() {
|
||||
let mut d: Vec<u8> = vec![];
|
||||
d.extend_from_slice(b"\x00\x00\x0b\x0cHello world");
|
||||
|
||||
let io = length_delimited::Builder::new()
|
||||
.length_field_offset(0)
|
||||
.length_field_length(3)
|
||||
.length_adjustment(0)
|
||||
.num_skip(4)
|
||||
.new_read(mock! {
|
||||
data(&d),
|
||||
});
|
||||
pin_mut!(io);
|
||||
|
||||
assert_next_eq!(io, b"Hello world");
|
||||
assert_done!(io);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn read_single_multi_frame_one_packet_length_includes_head() {
|
||||
let mut d: Vec<u8> = vec![];
|
||||
|
||||
Reference in New Issue
Block a user