package orwell.proxy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ZmqMessageWrapper {
	final static Logger logback = LoggerFactory.getLogger(ZmqMessageWrapper.class); 

	private String routingId;
	private String typeString;
    private EnumMessageType type;
    private byte[] message;
    private static final byte SPACE_CODE = 32; // ascii code of SPACE character
    private String zmqMessageString;
	
	public ZmqMessageWrapper(byte[] raw_zmq_message) {
		zmqMessageString = new String(raw_zmq_message);
		int indexType = 0;
		int indexMessage = 0;
		int index = 0;
		for (byte item : raw_zmq_message) {
			if (0 == indexType) {
				if (SPACE_CODE == item) {
					indexType = index + 1;
				}
			} else {
				if (SPACE_CODE == item) {
					indexMessage = index + 1;
					break;
				}
			}
			++index;
		}
		// routingID typeString message
		//           ^    ^
		//           |    indexMessage
		//           indexType
		int lengthRoutingID = indexType - 1;
        lengthRoutingID = (lengthRoutingID < 0) ? 0 : lengthRoutingID;
		int lengthType = indexMessage - indexType - 1;
        lengthType = (lengthType < 0) ? 0 : lengthType;
		routingId = new String(raw_zmq_message, 0, lengthRoutingID);
		typeString = new String(raw_zmq_message, indexType, lengthType);
        switch(typeString) {
            case "Registered":
                type = EnumMessageType.REGISTERED;
                break;
            case "Input":
                type = EnumMessageType.INPUT;
                break;
            case "GameState":
                type = EnumMessageType.GAMESTATE;
                break;
            case "ServerRobotState":
                type = EnumMessageType.SERVER_ROBOT_STATE;
                break;
            default:
                type = EnumMessageType.UNKNOWN;
                logback.warn("Message typeString unknown: " + typeString);
        }
		int lengthMessage = raw_zmq_message.length - lengthType
				- lengthRoutingID - 2;
        lengthMessage = (lengthMessage < 0) ? 0 : lengthMessage;
        message = new byte[lengthMessage];
		System.arraycopy(raw_zmq_message, indexMessage, message, 0,
				message.length);

		System.out.flush();
		logback.info("Message received: " + zmqMessageString);

		logback.info("Message [TYPE]: " + type);
	}

    public String getZmqMessageString() { return zmqMessageString; }

    public String getRoutingId() {
        return routingId;
    }

    public EnumMessageType getMessageType() {
        return type;
    }

    public byte[] getMessageBytes() {
        return message;
    }
}

@@ -2192,16 +2192,17 @@
 lush();%0A
+%0A
 %09%09logbac
@@ -2231,55 +2231,37 @@
 ed: 
-%22 + zmqMessageString);%0A%0A%09%09logback.info(%22Message
+%5BRoutingID%5D %22 + routingId + %22
  %5BTY

Change message log to be less verbose