@@ -775,13 +775,13 @@ public async Task<DeliveryResult<TKey, TValue>> ProduceAsync(
775
775
{
776
776
if ( keySerializer != null )
777
777
{
778
- keyBytes = keySerializer . Serialize ( message . Key , new SerializationContext ( MessageComponentType . Key , topicPartition . Topic , headers ) ) ? . AsMemory ( ) ;
778
+ SerializationContext ctx = new ( MessageComponentType . Key , topicPartition . Topic , headers ) ;
779
+ keyBytes = keySerializer . Serialize ( message . Key , ctx ) ? . AsMemory ( ) ;
779
780
}
780
781
else if ( asyncKeySerializer != null )
781
782
{
782
- keyBytes = ( await asyncKeySerializer . SerializeAsync ( message . Key ,
783
- new SerializationContext ( MessageComponentType . Key , topicPartition . Topic , headers ) )
784
- . ConfigureAwait ( false ) ) ? . AsMemory ( ) ;
783
+ SerializationContext ctx = new ( MessageComponentType . Key , topicPartition . Topic , headers ) ;
784
+ keyBytes = ( await asyncKeySerializer . SerializeAsync ( message . Key , ctx ) . ConfigureAwait ( false ) ) ? . AsMemory ( ) ;
785
785
}
786
786
else if ( message . Key is Memory < byte > memory )
787
787
{
@@ -809,13 +809,13 @@ public async Task<DeliveryResult<TKey, TValue>> ProduceAsync(
809
809
{
810
810
if ( valueSerializer != null )
811
811
{
812
- valBytes = valueSerializer . Serialize ( message . Value , new SerializationContext ( MessageComponentType . Value , topicPartition . Topic , headers ) ) ? . AsMemory ( ) ;
812
+ SerializationContext ctx = new ( MessageComponentType . Value , topicPartition . Topic , headers ) ;
813
+ valBytes = valueSerializer . Serialize ( message . Value , ctx ) ? . AsMemory ( ) ;
813
814
}
814
815
else if ( asyncValueSerializer != null )
815
816
{
816
- valBytes = ( await asyncValueSerializer . SerializeAsync ( message . Value ,
817
- new SerializationContext ( MessageComponentType . Value , topicPartition . Topic , headers ) )
818
- . ConfigureAwait ( false ) ) ? . AsMemory ( ) ;
817
+ SerializationContext ctx = new ( MessageComponentType . Value , topicPartition . Topic , headers ) ;
818
+ valBytes = ( await asyncValueSerializer . SerializeAsync ( message . Value , ctx ) . ConfigureAwait ( false ) ) ? . AsMemory ( ) ;
819
819
}
820
820
else if ( message . Value is Memory < byte > memory )
821
821
{
@@ -928,7 +928,8 @@ public void Produce(
928
928
{
929
929
if ( keySerializer != null )
930
930
{
931
- keyBytes = keySerializer . Serialize ( message . Key , new SerializationContext ( MessageComponentType . Key , topicPartition . Topic , headers ) ) ? . AsMemory ( ) ;
931
+ SerializationContext ctx = new ( MessageComponentType . Key , topicPartition . Topic , headers ) ;
932
+ keyBytes = keySerializer . Serialize ( message . Key , ctx ) ? . AsMemory ( ) ;
932
933
}
933
934
else if ( asyncKeySerializer != null )
934
935
{
@@ -960,7 +961,8 @@ public void Produce(
960
961
{
961
962
if ( valueSerializer != null )
962
963
{
963
- valBytes = valueSerializer . Serialize ( message . Value , new SerializationContext ( MessageComponentType . Value , topicPartition . Topic , headers ) ) ? . AsMemory ( ) ;
964
+ SerializationContext ctx = new ( MessageComponentType . Value , topicPartition . Topic , headers ) ;
965
+ valBytes = valueSerializer . Serialize ( message . Value , ctx ) ? . AsMemory ( ) ;
964
966
}
965
967
else if ( asyncValueSerializer != null )
966
968
{
0 commit comments