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

Function encode_decode_response

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

Source from the content-addressed store, hash-verified

278
279 #[test]
280 fn encode_decode_response() {
281 // Setup
282 let mut codec = ResponseCodec::new();
283 let mut buffer = BytesMut::new();
284
285 // Create a response with known data
286 let response = create_test_response();
287
288 // Encode the response
289 codec
290 .encode(response.clone(), &mut buffer)
291 .expect("should successfully encode response");
292
293 // Verify buffer has enough data (at least the header)
294 assert!(
295 buffer.len() >= 32,
296 "Buffer should contain at least the header"
297 );
298
299 // Decode the response
300 let decoded = codec
301 .decode(&mut buffer)
302 .expect("should successfully decode")
303 .expect("should have a decoded response");
304
305 // Verify decoded response matches original
306 assert_eq!(response.header.request_id, decoded.header.request_id);
307
308 if let ResponseBody::Begin(begin) = &response.body {
309 if let ResponseBody::Begin(decoded_begin) = &decoded.body {
310 assert_eq!(begin.kind, decoded_begin.kind);
311 assert_eq!(begin.payload, decoded_begin.payload);
312 } else {
313 panic!("Decoded response body should be Begin");
314 }
315 } else {
316 panic!("Response body should be Begin");
317 }
318
319 // Buffer should be empty after decoding
320 assert_eq!(buffer.len(), 0, "Buffer should be empty after decoding");
321 }
322
323 #[test]
324 fn partial_decode() {

Callers

nothing calls this directly

Calls 5

create_test_responseFunction · 0.85
expectMethod · 0.45
encodeMethod · 0.45
cloneMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected