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

Function decode_incomplete_data

libs/@local/codec/src/bytes.rs:325–349  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

323
324 #[test]
325 fn decode_incomplete_data() {
326 // Setup
327 let mut decoder = JsonLinesDecoder::<TestItem>::new();
328
329 // Create incomplete JSON (missing closing quote and brace)
330 let mut buffer = BytesMut::from(&br#"{"id":1,"name":"incomplete"#[..]);
331
332 // Without a newline, the decoder should return None
333 let result = decoder
334 .decode(&mut buffer)
335 .expect("should handle incomplete data without error");
336 assert!(result.is_none(), "Should not decode without newline");
337
338 // Add the closing quote, brace, and newline
339 buffer.extend_from_slice(b"\"}\n");
340
341 // Now it should decode successfully
342 let result = decoder
343 .decode(&mut buffer)
344 .expect("should successfully decode");
345 assert!(result.is_some(), "Should decode complete data");
346 let item = result.expect("should have a decoded item");
347 assert_eq!(item.id, 1);
348 assert_eq!(item.name, "incomplete");
349 }
350
351 #[test]
352 fn max_length() {

Callers

nothing calls this directly

Calls 4

fromFunction · 0.50
expectMethod · 0.45
decodeMethod · 0.45
extend_from_sliceMethod · 0.45

Tested by

no test coverage detected