public ResponseMessage DecodeMessage(IByteBuffer buffer, IMessageEncoderSelector encoderSelector, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); _stopwatch.Stop(); _networkDuration = _stopwatch.Elapsed; ResponseMessage message; _stopwatch.Restart(); using (var stream = new ByteBufferStream(buffer, ownsBuffer: false)) { var encoderFactory = new BinaryMessageEncoderFactory(stream, _messageEncoderSettings, _compressorSource); var opcode = PeekOpcode(stream); if (opcode == Opcode.Compressed) { var compresedMessageEncoder = encoderFactory.GetCompressedMessageEncoder(encoderSelector); var compressedMessage = (CompressedMessage)compresedMessageEncoder.ReadMessage(); message = (ResponseMessage)compressedMessage.OriginalMessage; } else { var encoder = encoderSelector.GetEncoder(encoderFactory); message = (ResponseMessage)encoder.ReadMessage(); } } _stopwatch.Stop(); _deserializationDuration = _stopwatch.Elapsed; return(message); }
private void CompressMessage( RequestMessage message, ByteBufferStream uncompressedMessageStream, ByteBufferStream compressedStream, MessageEncoderSettings messageEncoderSettings) { var compressedMessage = new CompressedMessage(message, uncompressedMessageStream, _sendCompressorType.Value); var compressedMessageEncoderFactory = new BinaryMessageEncoderFactory(compressedStream, messageEncoderSettings, _compressorSource); var compressedMessageEncoder = compressedMessageEncoderFactory.GetCompressedMessageEncoder(null); compressedMessageEncoder.WriteMessage(compressedMessage); }