@@ -111,15 +111,17 @@ public async Task ConnectAsync(CancellationToken cancellationToken)
111111 await _transport . ConnectAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
112112
113113 _receiveMessagesCancellationTokenSource = new CancellationTokenSource ( ) ;
114- _receivingMessageTask = _myTaskFactory . StartNew ( async ( ) => await ReceiveMessagesAsync ( _receiveMessagesCancellationTokenSource . Token ) , TaskCreationOptions . LongRunning ) . Unwrap ( ) ;
115- _eventEmitterTask = _myTaskFactory . StartNew ( async ( ) => await ProcessEventsAwaiterAsync ( ) , TaskCreationOptions . LongRunning ) . Unwrap ( ) ;
114+ _receivingMessageTask = _myTaskFactory . StartNew ( async ( ) => await ReceiveMessagesAsync ( _receiveMessagesCancellationTokenSource . Token ) ) . Unwrap ( ) ;
115+ _eventEmitterTask = _myTaskFactory . StartNew ( ProcessEventsAwaiterAsync ) . Unwrap ( ) ;
116116 }
117117
118118 private async Task ReceiveMessagesAsync ( CancellationToken cancellationToken )
119119 {
120120 while ( ! cancellationToken . IsCancellationRequested )
121121 {
122- var message = await _transport . ReceiveAsJsonAsync < Message > ( _jsonSerializerContext , cancellationToken ) ;
122+ var data = await _transport . ReceiveAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
123+
124+ var message = JsonSerializer . Deserialize ( new ReadOnlySpan < byte > ( data ) , _jsonSerializerContext . Message ) ;
123125
124126 switch ( message )
125127 {
@@ -179,21 +181,21 @@ private async Task ProcessEventsAwaiterAsync()
179181 }
180182
181183 public async Task < TResult > ExecuteCommandAsync < TCommand , TResult > ( TCommand command , CommandOptions ? options )
182- where TCommand : Command
184+ where TCommand : Command
183185 {
184186 var jsonElement = await ExecuteCommandCoreAsync ( command , options ) . ConfigureAwait ( false ) ;
185187
186188 return ( TResult ) jsonElement . Deserialize ( typeof ( TResult ) , _jsonSerializerContext ) ! ;
187189 }
188190
189191 public async Task ExecuteCommandAsync < TCommand > ( TCommand command , CommandOptions ? options )
190- where TCommand : Command
192+ where TCommand : Command
191193 {
192194 await ExecuteCommandCoreAsync ( command , options ) . ConfigureAwait ( false ) ;
193195 }
194196
195197 private async Task < JsonElement > ExecuteCommandCoreAsync < TCommand > ( TCommand command , CommandOptions ? options )
196- where TCommand : Command
198+ where TCommand : Command
197199 {
198200 command . Id = Interlocked . Increment ( ref _currentCommandId ) ;
199201
@@ -207,7 +209,9 @@ private async Task<JsonElement> ExecuteCommandCoreAsync<TCommand>(TCommand comma
207209
208210 _pendingCommands [ command . Id ] = tcs ;
209211
210- await _transport . SendAsJsonAsync ( command , _jsonSerializerContext , cts . Token ) . ConfigureAwait ( false ) ;
212+ var data = JsonSerializer . SerializeToUtf8Bytes ( command , typeof ( TCommand ) , _jsonSerializerContext ) ;
213+
214+ await _transport . SendAsync ( data , cts . Token ) . ConfigureAwait ( false ) ;
211215
212216 return await tcs . Task . ConfigureAwait ( false ) ;
213217 }
0 commit comments