@@ -348,18 +348,7 @@ public static ByteBuffer serializeMetadata(ArrowMessage message, IpcOption write
348348 public static ArrowRecordBatch deserializeRecordBatch (
349349 Message recordBatchMessage , ArrowBuf bodyBuffer ) throws IOException {
350350 RecordBatch recordBatchFB = (RecordBatch ) recordBatchMessage .header (new RecordBatch ());
351- // Extract custom metadata from the Message
352- Map <String , String > customMetadata = null ;
353- if (recordBatchMessage .customMetadataLength () > 0 ) {
354- customMetadata = new HashMap <>();
355- for (int i = 0 ; i < recordBatchMessage .customMetadataLength (); i ++) {
356- KeyValue kv = recordBatchMessage .customMetadata (i );
357- String key = kv .key ();
358- String value = kv .value ();
359- customMetadata .put (key == null ? "" : key , value == null ? "" : value );
360- }
361- }
362- return deserializeRecordBatch (recordBatchFB , bodyBuffer , customMetadata );
351+ return deserializeRecordBatch (recordBatchFB , bodyBuffer , getCustomMetadata (recordBatchMessage ));
363352 }
364353
365354 /**
@@ -414,22 +403,10 @@ public static ArrowRecordBatch deserializeRecordBatch(
414403
415404 RecordBatch recordBatchFB = (RecordBatch ) messageFB .header (new RecordBatch ());
416405
417- // Extract custom metadata from the Message
418- Map <String , String > customMetadata = null ;
419- if (messageFB .customMetadataLength () > 0 ) {
420- customMetadata = new HashMap <>();
421- for (int i = 0 ; i < messageFB .customMetadataLength (); i ++) {
422- KeyValue kv = messageFB .customMetadata (i );
423- String key = kv .key ();
424- String value = kv .value ();
425- customMetadata .put (key == null ? "" : key , value == null ? "" : value );
426- }
427- }
428-
429406 // Now read the body
430407 final ArrowBuf body =
431408 buffer .slice (block .getMetadataLength (), totalLen - block .getMetadataLength ());
432- return deserializeRecordBatch (recordBatchFB , body , customMetadata );
409+ return deserializeRecordBatch (recordBatchFB , body , getCustomMetadata ( messageFB ) );
433410 }
434411
435412 /**
@@ -839,4 +816,18 @@ public static ArrowBuf readMessageBody(ReadChannel in, long bodyLength, BufferAl
839816 }
840817 return bodyBuffer ;
841818 }
819+
820+ private static Map <String , String > getCustomMetadata (Message message ) {
821+ if (message .customMetadataLength () == 0 ) {
822+ return null ;
823+ }
824+ Map <String , String > customMetadata = new HashMap <>();
825+ for (int i = 0 ; i < message .customMetadataLength (); i ++) {
826+ KeyValue kv = message .customMetadata (i );
827+ String key = kv .key ();
828+ String value = kv .value ();
829+ customMetadata .put (key == null ? "" : key , value == null ? "" : value );
830+ }
831+ return customMetadata ;
832+ }
842833}
0 commit comments