@@ -557,7 +557,6 @@ private void InitializeSerializers(
557
557
throw new ArgumentNullException (
558
558
$ "Value serializer not specified and there is no default serializer defined for type { typeof ( TValue ) . Name } .") ;
559
559
}
560
-
561
560
}
562
561
else if ( valueSerializer == null && asyncValueSerializer != null )
563
562
{
@@ -776,13 +775,13 @@ public async Task<DeliveryResult<TKey, TValue>> ProduceAsync(
776
775
{
777
776
if ( keySerializer != null )
778
777
{
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 ( ) ;
781
779
}
782
780
else if ( asyncKeySerializer != null )
783
781
{
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 ( ) ;
786
785
}
787
786
else if ( message . Key is Memory < byte > memory )
788
787
{
@@ -810,13 +809,13 @@ public async Task<DeliveryResult<TKey, TValue>> ProduceAsync(
810
809
{
811
810
if ( valueSerializer != null )
812
811
{
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 ( ) ;
815
813
}
816
814
else if ( asyncValueSerializer != null )
817
815
{
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 ( ) ;
820
819
}
821
820
else if ( message . Value is Memory < byte > memory )
822
821
{
@@ -929,8 +928,7 @@ public void Produce(
929
928
{
930
929
if ( keySerializer != null )
931
930
{
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 ( ) ;
934
932
}
935
933
else if ( asyncKeySerializer != null )
936
934
{
@@ -962,8 +960,7 @@ public void Produce(
962
960
{
963
961
if ( valueSerializer != null )
964
962
{
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 ( ) ;
967
964
}
968
965
else if ( asyncValueSerializer != null )
969
966
{
0 commit comments