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

Function encode_decode_request

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

Source from the content-addressed store, hash-verified

233
234 #[test]
235 fn encode_decode_request() {
236 // Setup
237 let mut codec = RequestCodec::new();
238 let mut buffer = BytesMut::new();
239
240 // Create a request with known data
241 let request = create_test_request();
242
243 // Encode the request
244 codec
245 .encode(request.clone(), &mut buffer)
246 .expect("should successfully encode request");
247
248 // Verify buffer has enough data (at least the header)
249 assert!(
250 buffer.len() >= 32,
251 "Buffer should contain at least the header"
252 );
253
254 // Decode the request
255 let decoded = codec
256 .decode(&mut buffer)
257 .expect("should successfully decode")
258 .expect("should have a decoded request");
259
260 // Verify decoded request matches original
261 assert_eq!(request.header.request_id, decoded.header.request_id);
262
263 if let RequestBody::Begin(begin) = &request.body {
264 if let RequestBody::Begin(decoded_begin) = &decoded.body {
265 assert_eq!(begin.subsystem.id, decoded_begin.subsystem.id);
266 assert_eq!(begin.procedure.id, decoded_begin.procedure.id);
267 assert_eq!(begin.payload, decoded_begin.payload);
268 } else {
269 panic!("Decoded request body should be Begin");
270 }
271 } else {
272 panic!("Request body should be Begin");
273 }
274
275 // Buffer should be empty after decoding
276 assert_eq!(buffer.len(), 0, "Buffer should be empty after decoding");
277 }
278
279 #[test]
280 fn encode_decode_response() {

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected