/// <inheritdoc/> public override void FilterWrite(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest) { Object message = writeRequest.Message; // Bypass the encoding if the message is contained in a IoBuffer, // as it has already been encoded before if (message is IoBuffer || message is IFileRegion) { nextFilter.FilterWrite(session, writeRequest); return; } // Get the encoder in the session IProtocolEncoder encoder = _factory.GetEncoder(session); IProtocolEncoderOutput encoderOut = GetEncoderOut(session, nextFilter, writeRequest); if (encoder == null) { throw new ProtocolEncoderException("The encoder is null for the session " + session); } if (encoderOut == null) { throw new ProtocolEncoderException("The encoderOut is null for the session " + session); } try { encoder.Encode(session, message, encoderOut); AbstractProtocolEncoderOutput ape = encoderOut as AbstractProtocolEncoderOutput; if (ape != null) { // Send it directly IQueue <Object> bufferQueue = ape.MessageQueue; // Write all the encoded messages now while (!bufferQueue.IsEmpty) { Object encodedMessage = bufferQueue.Dequeue(); if (encodedMessage == null) { break; } // Flush only when the buffer has remaining. IoBuffer buf = encodedMessage as IoBuffer; if (buf == null || buf.HasRemaining) { IWriteRequest encodedWriteRequest = new EncodedWriteRequest(encodedMessage, null, writeRequest.Destination); nextFilter.FilterWrite(session, encodedWriteRequest); } } } // Call the next filter nextFilter.FilterWrite(session, new MessageWriteRequest(writeRequest)); } catch (Exception ex) { ProtocolEncoderException pee = ex as ProtocolEncoderException; if (pee == null) { pee = new ProtocolEncoderException(null, ex); } throw pee; } }
public ProtocolCodecSession() { _notWrittenFuture = DefaultWriteFuture.NewNotWrittenFuture(this, new NotImplementedException()); _encoderOutput = new DummyProtocolEncoderOutput(_notWrittenFuture); _decoderOutput = new DummyProtocolDecoderOutput(); }
public ProtocolCodecSession() { _notWrittenFuture = DefaultWriteFuture.NewNotWrittenFuture(this, new NotImplementedException()); _encoderOutput = new DummyProtocolEncoderOutput(_notWrittenFuture); _decoderOutput = new DummyProtocolDecoderOutput(); }