public static void encodePacket(Packet packet, EncodeCallback callback) {
        if (packet.data instanceof byte[]) {
            @SuppressWarnings("unchecked")
            Packet<byte[]> _packet = packet;
            @SuppressWarnings("unchecked")
            EncodeCallback<byte[]> _callback = callback;
            encodeByteArray(_packet, _callback);
            return;
        }

        String encoded = String.valueOf(packets.get(packet.type));

        if (null != packet.data) {
            encoded += UTF8.encode(String.valueOf(packet.data));
        }

        @SuppressWarnings("unchecked")
        EncodeCallback<String> _callback = callback;
        _callback.call(encoded);
    }