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

Function encode_decode_single_item

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

Source from the content-addressed store, hash-verified

249
250 #[test]
251 fn encode_decode_single_item() {
252 // Setup
253 let test_item = TestItem {
254 id: 1,
255 name: "test".to_owned(),
256 };
257 let mut encoder = JsonLinesEncoder::<TestItem>::default();
258 let mut decoder = JsonLinesDecoder::<TestItem>::new();
259 let mut buffer = BytesMut::new();
260
261 // Encode
262 encoder
263 .encode(test_item.clone(), &mut buffer)
264 .expect("should successfully encode");
265
266 // Decode
267 let decoded_item = decoder
268 .decode(&mut buffer)
269 .expect("should successfully decode")
270 .expect("should have a decoded item");
271
272 // Verify
273 assert_eq!(test_item, decoded_item);
274 assert!(
275 decoder
276 .decode(&mut buffer)
277 .expect("should successfully decode")
278 .is_none(),
279 "Should have no more items"
280 );
281 }
282
283 #[test]
284 fn encode_decode_multiple_items() {

Callers

nothing calls this directly

Calls 6

defaultFunction · 0.50
to_ownedMethod · 0.45
expectMethod · 0.45
encodeMethod · 0.45
cloneMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected