{
if (null == msg)
{
return msg;
}
Event event = (Event) msg;
ChannelBuffer opcode = ChannelBuffers.buffer(1);
opcode.writeByte(event.getType());
if (Events.LOG_IN == event.getType() || Events.RECONNECT == event.getType())
{
// write protocol version also
ChannelBuffer protocolVersion = ChannelBuffers.buffer(1);
protocolVersion.writeByte(Events.PROTOCOL_VERSION);
opcode = ChannelBuffers.wrappedBuffer(opcode, protocolVersion);
}
ChannelBuffer buffer = null;
if (null != event.getSource())
{
@SuppressWarnings("unchecked")
MessageBuffer<ChannelBuffer> msgBuffer = (MessageBuffer<ChannelBuffer>) event
.getSource();
ChannelBuffer data = msgBuffer.getNativeBuffer();
buffer = ChannelBuffers.wrappedBuffer(opcode, data);
}
else