@@ -775,13 +775,13 @@ public async Task<DeliveryResult<TKey, TValue>> ProduceAsync(
775775 {
776776 if ( keySerializer != null )
777777 {
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 ( ) ;
779780 }
780781 else if ( asyncKeySerializer != null )
781782 {
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 ( ) ;
785785 }
786786 else if ( message . Key is Memory < byte > memory )
787787 {
@@ -809,13 +809,13 @@ public async Task<DeliveryResult<TKey, TValue>> ProduceAsync(
809809 {
810810 if ( valueSerializer != null )
811811 {
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 ( ) ;
813814 }
814815 else if ( asyncValueSerializer != null )
815816 {
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 ( ) ;
819819 }
820820 else if ( message . Value is Memory < byte > memory )
821821 {
@@ -928,7 +928,8 @@ public void Produce(
928928 {
929929 if ( keySerializer != null )
930930 {
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 ( ) ;
932933 }
933934 else if ( asyncKeySerializer != null )
934935 {
@@ -960,7 +961,8 @@ public void Produce(
960961 {
961962 if ( valueSerializer != null )
962963 {
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 ( ) ;
964966 }
965967 else if ( asyncValueSerializer != null )
966968 {
0 commit comments