MCPcopy Create free account
hub / github.com/hashintel/hash / partial_decode

Function partial_decode

libs/@local/codec/src/harpc/wire.rs:324–366  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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() {

Callers

nothing calls this directly

Calls 6

create_test_requestFunction · 0.85
fromFunction · 0.50
expectMethod · 0.45
encodeMethod · 0.45
cloneMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected