LengthDelimitedCodec::builder()
.length_field_offset(0) // default value
.length_field_type::<u16>()
.length_adjustment(0) // default value
.num_skip(0) // Do not strip frame header
.new_read(io);
The following frame will be decoded as such:
INPUT DECODED
+-- len ---+--- Payload ---+ +-- len ---+--- Payload ---+
| \x00\x0B | Hello world | --> | \x00\x0B | Hello world |
+----------+---------------+ +----------+---------------+
However, the following (new) test fails in tokio-util/tests/length_delimited.rs:
The last two bytes of "world" is missing. With a longer size prefix (u32), the number of missing byte increases (4). It appears to me that the logic that reads the size advances the pointer, but this is incorrectly adjusted later, when num_skip(0) is taken into account.
A possible workaround:
.length_adjustment(2) # 2 must match the size prefix size.
Version
tokio master branch (14c17fc09656a30230177b600bacceb9db33e942, tokio 1.38.0), also tokio-util 0.7.11.
Platform
Linux
Description
The documentation gives this example:
The following frame will be decoded as such:
However, the following (new) test fails in tokio-util/tests/length_delimited.rs:
Error message:
The last two bytes of "world" is missing. With a longer size prefix (u32), the number of missing byte increases (4). It appears to me that the logic that reads the size advances the pointer, but this is incorrectly adjusted later, when num_skip(0) is taken into account.
A possible workaround: