| 322 | |
| 323 | #[test] |
| 324 | fn partial_decode() { |
| 325 | // Setup |
| 326 | let mut codec = RequestCodec::new(); |
| 327 | let mut buffer = BytesMut::new(); |
| 328 | |
| 329 | // Create a request with known data |
| 330 | let request = create_test_request(); |
| 331 | |
| 332 | // Encode the request |
| 333 | codec |
| 334 | .encode(request, &mut buffer) |
| 335 | .expect("should successfully encode request"); |
| 336 | |
| 337 | // Save the full buffer |
| 338 | let full_buffer = buffer.clone(); |
| 339 | |
| 340 | // Create a partial buffer with only 20 bytes (less than header) |
| 341 | let mut partial_buffer = BytesMut::from(&full_buffer[..20]); |
| 342 | |
| 343 | // Try to decode from partial buffer (should return None) |
| 344 | let result = codec |
| 345 | .decode(&mut partial_buffer) |
| 346 | .expect("should handle partial decode without error"); |
| 347 | |
| 348 | assert!( |
| 349 | result.is_none(), |
| 350 | "Partial decode should return None when buffer has less than header size" |
| 351 | ); |
| 352 | |
| 353 | // Create a partial buffer with header but incomplete payload |
| 354 | let header_size = 32; |
| 355 | let mut header_only_buffer = BytesMut::from(&full_buffer[..=header_size]); |
| 356 | |
| 357 | // Try to decode from header-only buffer (should return None) |
| 358 | let result = codec |
| 359 | .decode(&mut header_only_buffer) |
| 360 | .expect("should handle header-only decode without error"); |
| 361 | |
| 362 | assert!( |
| 363 | result.is_none(), |
| 364 | "Partial decode should return None when buffer has incomplete payload" |
| 365 | ); |
| 366 | } |
| 367 | |
| 368 | #[test] |
| 369 | fn zero_length_payload() { |