@Override
    public ChannelBuffer getEncodedMessage() {
        ChannelBuffer encodedMessage = ChannelBuffers.dynamicBuffer();
        encodedMessage.writeBytes("Command: ServerMessage\n".getBytes(CharsetUtil.UTF_8));
        encodedMessage.writeBytes(("Group: " + _group + "\n").getBytes(CharsetUtil.UTF_8));
        StringBuilder builder = new StringBuilder();
        for (String extension : _peerMessage.getExtensions()) {
            builder.append(extension);
            builder.append(", ");
        }
        if (_peerMessage instanceof TextMessage) {
            TextMessage tm = (TextMessage) _peerMessage;
            encodedMessage.writeBytes("Command: Message\n".getBytes(CharsetUtil.UTF_8));
            encodedMessage.writeBytes(("Id: " + _peerMessage.getId() + "\n").getBytes(CharsetUtil.UTF_8));
            encodedMessage.writeBytes(("Sender: " + _peerMessage.getSender() + "\n").getBytes(CharsetUtil.UTF_8));
            encodedMessage.writeBytes(("Share: " + tm.isShare() + "\n").getBytes(CharsetUtil.UTF_8));
            encodedMessage.writeBytes(("Extensions: " + builder + "\n").getBytes(CharsetUtil.UTF_8));
            encodedMessage.writeBytes(("Length: " + tm.getLength() + "\n").getBytes(CharsetUtil.UTF_8));
            encodedMessage.writeBytes((tm.getText() + "\n").getBytes(CharsetUtil.UTF_8));
        } else if (_peerMessage instanceof TextMessage2) {
            TextMessage2 tm2 = (TextMessage2) _peerMessage;
            encodedMessage.writeBytes("Command: Message2\n".getBytes(CharsetUtil.UTF_8));
            encodedMessage.writeBytes(("Id: " + _peerMessage.getId() + "\n").getBytes(CharsetUtil.UTF_8));
            encodedMessage.writeBytes(("Sender: " + _peerMessage.getSender() + "\n").getBytes(CharsetUtil.UTF_8));
            encodedMessage.writeBytes(("Share: " + tm2.getDateTime() + "\n").getBytes(CharsetUtil.UTF_8));
            encodedMessage.writeBytes(("Extensions: " + builder + "\n").getBytes(CharsetUtil.UTF_8));
            encodedMessage.writeBytes(("Length: " + tm2.getLength() + "\n").getBytes(CharsetUtil.UTF_8));
            encodedMessage.writeBytes((tm2.getText() + "\n").getBytes(CharsetUtil.UTF_8));
        } else if (_peerMessage instanceof CustomMessage) {
            CustomMessage cm = (CustomMessage) _peerMessage;
            encodedMessage.writeBytes("Command: Custom\n".getBytes(CharsetUtil.UTF_8));
            encodedMessage.writeBytes(("Id: " + _peerMessage.getId() + "\n").getBytes(CharsetUtil.UTF_8));
            encodedMessage.writeBytes(("Sender: " + _peerMessage.getSender() + "\n").getBytes(CharsetUtil.UTF_8));
            encodedMessage.writeBytes(("Share: " + cm.getDateTime() + "\n").getBytes(CharsetUtil.UTF_8));
            encodedMessage.writeBytes(("Extensions: " + builder + "\n").getBytes(CharsetUtil.UTF_8));
            encodedMessage.writeBytes(("Length: " + cm.getLength() + "\n").getBytes(CharsetUtil.UTF_8));
            encodedMessage.writeBytes((cm.getText() + "\n").getBytes(CharsetUtil.UTF_8));
        }
        encodedMessage.writeBytes("\n".getBytes(CharsetUtil.UTF_8));
        encodedMessage = encodedMessage.slice(0, encodedMessage.writerIndex());
        return encodedMessage;

    }