@@ -557,7 +557,6 @@ private void InitializeSerializers(
557557 throw new ArgumentNullException (
558558 $ "Value serializer not specified and there is no default serializer defined for type { typeof ( TValue ) . Name } .") ;
559559 }
560-
561560 }
562561 else if ( valueSerializer == null && asyncValueSerializer != null )
563562 {
@@ -776,13 +775,13 @@ public async Task<DeliveryResult<TKey, TValue>> ProduceAsync(
776775 {
777776 if ( keySerializer != null )
778777 {
779- byte [ ] keyBytesArray = keySerializer . Serialize ( message . Key , new SerializationContext ( MessageComponentType . Key , topicPartition . Topic , headers ) ) ;
780- keyBytes = keyBytesArray == null ? ( ReadOnlyMemory < byte > ? ) null : keyBytesArray ;
778+ keyBytes = keySerializer . Serialize ( message . Key , new SerializationContext ( MessageComponentType . Key , topicPartition . Topic , headers ) ) ? . AsMemory ( ) ;
781779 }
782780 else if ( asyncKeySerializer != null )
783781 {
784- byte [ ] keyBytesArray = await asyncKeySerializer . SerializeAsync ( message . Key , new SerializationContext ( MessageComponentType . Key , topicPartition . Topic , headers ) ) . ConfigureAwait ( false ) ;
785- keyBytes = keyBytesArray == null ? ( ReadOnlyMemory < byte > ? ) null : keyBytesArray ;
782+ keyBytes = ( await asyncKeySerializer . SerializeAsync ( message . Key ,
783+ new SerializationContext ( MessageComponentType . Key , topicPartition . Topic , headers ) )
784+ . ConfigureAwait ( false ) ) ? . AsMemory ( ) ;
786785 }
787786 else if ( message . Key is Memory < byte > memory )
788787 {
@@ -810,13 +809,13 @@ public async Task<DeliveryResult<TKey, TValue>> ProduceAsync(
810809 {
811810 if ( valueSerializer != null )
812811 {
813- byte [ ] valueBytesArray = valueSerializer . Serialize ( message . Value , new SerializationContext ( MessageComponentType . Value , topicPartition . Topic , headers ) ) ;
814- valBytes = valueBytesArray == null ? ( ReadOnlyMemory < byte > ? ) null : valueBytesArray ;
812+ valBytes = valueSerializer . Serialize ( message . Value , new SerializationContext ( MessageComponentType . Value , topicPartition . Topic , headers ) ) ? . AsMemory ( ) ;
815813 }
816814 else if ( asyncValueSerializer != null )
817815 {
818- byte [ ] valueBytesArray = await asyncValueSerializer . SerializeAsync ( message . Value , new SerializationContext ( MessageComponentType . Value , topicPartition . Topic , headers ) ) . ConfigureAwait ( false ) ;
819- valBytes = valueBytesArray == null ? ( ReadOnlyMemory < byte > ? ) null : valueBytesArray ;
816+ valBytes = ( await asyncValueSerializer . SerializeAsync ( message . Value ,
817+ new SerializationContext ( MessageComponentType . Value , topicPartition . Topic , headers ) )
818+ . ConfigureAwait ( false ) ) ? . AsMemory ( ) ;
820819 }
821820 else if ( message . Value is Memory < byte > memory )
822821 {
@@ -929,8 +928,7 @@ public void Produce(
929928 {
930929 if ( keySerializer != null )
931930 {
932- byte [ ] keyBytesArray = keySerializer . Serialize ( message . Key , new SerializationContext ( MessageComponentType . Key , topicPartition . Topic , headers ) ) ;
933- keyBytes = keyBytesArray == null ? ( ReadOnlyMemory < byte > ? ) null : keyBytesArray ;
931+ keyBytes = keySerializer . Serialize ( message . Key , new SerializationContext ( MessageComponentType . Key , topicPartition . Topic , headers ) ) ? . AsMemory ( ) ;
934932 }
935933 else if ( asyncKeySerializer != null )
936934 {
@@ -962,8 +960,7 @@ public void Produce(
962960 {
963961 if ( valueSerializer != null )
964962 {
965- byte [ ] valueBytesArray = valueSerializer . Serialize ( message . Value , new SerializationContext ( MessageComponentType . Value , topicPartition . Topic , headers ) ) ;
966- valBytes = valueBytesArray == null ? ( ReadOnlyMemory < byte > ? ) null : valueBytesArray ;
963+ valBytes = valueSerializer . Serialize ( message . Value , new SerializationContext ( MessageComponentType . Value , topicPartition . Topic , headers ) ) ? . AsMemory ( ) ;
967964 }
968965 else if ( asyncValueSerializer != null )
969966 {
0 commit comments