@@ -27,7 +27,10 @@ use tokio::{
27
27
} ;
28
28
use tracing:: { debug, info, warn} ;
29
29
30
- use crate :: protocol:: { messages:: ApiVersionsRequest , traits:: ReadType } ;
30
+ use crate :: protocol:: {
31
+ messages:: { ApiVersionsRequest , ResponseBodyWithMetadata } ,
32
+ traits:: ReadType ,
33
+ } ;
31
34
use crate :: {
32
35
backoff:: ErrorOrThrottle ,
33
36
protocol:: {
@@ -315,6 +318,19 @@ where
315
318
}
316
319
317
320
pub async fn request < R > ( & self , msg : R ) -> Result < R :: ResponseBody , RequestError >
321
+ where
322
+ R : RequestBody + Send + WriteVersionedType < Vec < u8 > > ,
323
+ R :: ResponseBody : ReadVersionedType < Cursor < Vec < u8 > > > ,
324
+ {
325
+ self . request_with_version_ranges ( msg, & self . version_ranges )
326
+ . await
327
+ . map ( |body| body. response )
328
+ }
329
+
330
+ pub async fn request_with_metadata < R > (
331
+ & self ,
332
+ msg : R ,
333
+ ) -> Result < ResponseBodyWithMetadata < R :: ResponseBody > , RequestError >
318
334
where
319
335
R : RequestBody + Send + WriteVersionedType < Vec < u8 > > ,
320
336
R :: ResponseBody : ReadVersionedType < Cursor < Vec < u8 > > > ,
@@ -327,7 +343,7 @@ where
327
343
& self ,
328
344
msg : R ,
329
345
version_ranges : & HashMap < ApiKey , ApiVersionRange > ,
330
- ) -> Result < R :: ResponseBody , RequestError >
346
+ ) -> Result < ResponseBodyWithMetadata < R :: ResponseBody > , RequestError >
331
347
where
332
348
R : RequestBody + Send + WriteVersionedType < Vec < u8 > > ,
333
349
R :: ResponseBody : ReadVersionedType < Cursor < Vec < u8 > > > ,
@@ -371,6 +387,7 @@ where
371
387
. write_versioned ( & mut buf, header_version)
372
388
. expect ( "Writing header to buffer should always work" ) ;
373
389
msg. write_versioned ( & mut buf, body_api_version) ?;
390
+ let encoded_size = buf. len ( ) ;
374
391
375
392
let ( tx, rx) = channel ( ) ;
376
393
@@ -412,7 +429,10 @@ where
412
429
} ) ;
413
430
}
414
431
415
- Ok ( body)
432
+ Ok ( ResponseBodyWithMetadata {
433
+ response : body,
434
+ encoded_request_size : encoded_size,
435
+ } )
416
436
}
417
437
418
438
async fn send_message ( & self , msg : Vec < u8 > ) -> Result < ( ) , RequestError > {
@@ -468,7 +488,7 @@ where
468
488
. request_with_version_ranges ( & body, & version_ranges)
469
489
. await
470
490
{
471
- Ok ( response) => {
491
+ Ok ( ResponseBodyWithMetadata { response, .. } ) => {
472
492
if let Err ( ErrorOrThrottle :: Throttle ( throttle) ) =
473
493
maybe_throttle :: < SyncVersionsError > ( response. throttle_time_ms )
474
494
{
0 commit comments