package electrosphere.net.parser.net.message;

import electrosphere.net.parser.util.ByteStreamUtils;
import electrosphere.net.parser.net.raw.CircularByteBuffer;
import java.util.LinkedList;
import java.util.List;

public class InventoryMessage extends NetworkMessage {

    public enum InventoryMessageType {
        ADDITEMTOINVENTORY,
        REMOVEITEMFROMINVENTORY,
        CLIENTREQUESTEQUIPITEM,
        SERVERCOMMANDMOVEITEMCONTAINER,
        SERVERCOMMANDEQUIPITEM,
        SERVERCOMMANDUNEQUIPITEM,
        CLIENTREQUESTUNEQUIPITEM,
        CLIENTREQUESTPERFORMITEMACTION,
    }

    InventoryMessageType messageType;
    String itemTemplate;
    String equipPointId;
    int entityId;
    int equipperId;
    int containerType;
    int itemActionCode;
    int itemActionCodeState;

    InventoryMessage(InventoryMessageType messageType){
        this.type = MessageType.INVENTORY_MESSAGE;
        this.messageType = messageType;
    }

    public InventoryMessageType getMessageSubtype(){
        return this.messageType;
    }

    public String getitemTemplate() {
        return itemTemplate;
    }

    public void setitemTemplate(String itemTemplate) {
        this.itemTemplate = itemTemplate;
    }

    public String getequipPointId() {
        return equipPointId;
    }

    public void setequipPointId(String equipPointId) {
        this.equipPointId = equipPointId;
    }

    public int getentityId() {
        return entityId;
    }

    public void setentityId(int entityId) {
        this.entityId = entityId;
    }

    public int getequipperId() {
        return equipperId;
    }

    public void setequipperId(int equipperId) {
        this.equipperId = equipperId;
    }

    public int getcontainerType() {
        return containerType;
    }

    public void setcontainerType(int containerType) {
        this.containerType = containerType;
    }

    public int getitemActionCode() {
        return itemActionCode;
    }

    public void setitemActionCode(int itemActionCode) {
        this.itemActionCode = itemActionCode;
    }

    public int getitemActionCodeState() {
        return itemActionCodeState;
    }

    public void setitemActionCodeState(int itemActionCodeState) {
        this.itemActionCodeState = itemActionCodeState;
    }

    static void stripPacketHeader(CircularByteBuffer byteBuffer){
        byteBuffer.read(2);
    }

    public static boolean canParseMessage(CircularByteBuffer byteBuffer, byte secondByte){
        switch(secondByte){
            case TypeBytes.INVENTORY_MESSAGE_TYPE_ADDITEMTOINVENTORY:
                return InventoryMessage.canParseaddItemToInventoryMessage(byteBuffer);
            case TypeBytes.INVENTORY_MESSAGE_TYPE_REMOVEITEMFROMINVENTORY:
                if(byteBuffer.getRemaining() >= TypeBytes.INVENTORY_MESSAGE_TYPE_REMOVEITEMFROMINVENTORY_SIZE){
                    return true;
                } else {
                    return false;
                }
            case TypeBytes.INVENTORY_MESSAGE_TYPE_CLIENTREQUESTEQUIPITEM:
                return InventoryMessage.canParseclientRequestEquipItemMessage(byteBuffer);
            case TypeBytes.INVENTORY_MESSAGE_TYPE_SERVERCOMMANDMOVEITEMCONTAINER:
                return InventoryMessage.canParseserverCommandMoveItemContainerMessage(byteBuffer);
            case TypeBytes.INVENTORY_MESSAGE_TYPE_SERVERCOMMANDEQUIPITEM:
                return InventoryMessage.canParseserverCommandEquipItemMessage(byteBuffer);
            case TypeBytes.INVENTORY_MESSAGE_TYPE_SERVERCOMMANDUNEQUIPITEM:
                return InventoryMessage.canParseserverCommandUnequipItemMessage(byteBuffer);
            case TypeBytes.INVENTORY_MESSAGE_TYPE_CLIENTREQUESTUNEQUIPITEM:
                return InventoryMessage.canParseclientRequestUnequipItemMessage(byteBuffer);
            case TypeBytes.INVENTORY_MESSAGE_TYPE_CLIENTREQUESTPERFORMITEMACTION:
                return InventoryMessage.canParseclientRequestPerformItemActionMessage(byteBuffer);
        }
        return false;
    }

    public static boolean canParseaddItemToInventoryMessage(CircularByteBuffer byteBuffer){
        int currentStreamLength = byteBuffer.getRemaining();
        List<Byte> temporaryByteQueue = new LinkedList<Byte>();
        if(currentStreamLength < 6){
            return false;
        }
        int itemTemplateSize = 0;
        if(currentStreamLength < 10){
            return false;
        } else {
            temporaryByteQueue.add(byteBuffer.peek(6 + 0));
            temporaryByteQueue.add(byteBuffer.peek(6 + 1));
            temporaryByteQueue.add(byteBuffer.peek(6 + 2));
            temporaryByteQueue.add(byteBuffer.peek(6 + 3));
            itemTemplateSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue);
        }
        if(currentStreamLength < 10 + itemTemplateSize){
            return false;
        }
        return true;
    }

    public static InventoryMessage parseaddItemToInventoryMessage(CircularByteBuffer byteBuffer){
        InventoryMessage rVal = new InventoryMessage(InventoryMessageType.ADDITEMTOINVENTORY);
        stripPacketHeader(byteBuffer);
        rVal.setentityId(ByteStreamUtils.popIntFromByteQueue(byteBuffer));
        rVal.setitemTemplate(ByteStreamUtils.popStringFromByteQueue(byteBuffer));
        return rVal;
    }

    public static InventoryMessage constructaddItemToInventoryMessage(int entityId,String itemTemplate){
        InventoryMessage rVal = new InventoryMessage(InventoryMessageType.ADDITEMTOINVENTORY);
        rVal.setentityId(entityId);
        rVal.setitemTemplate(itemTemplate);
        rVal.serialize();
        return rVal;
    }

    public static InventoryMessage parseremoveItemFromInventoryMessage(CircularByteBuffer byteBuffer){
        InventoryMessage rVal = new InventoryMessage(InventoryMessageType.REMOVEITEMFROMINVENTORY);
        stripPacketHeader(byteBuffer);
        rVal.setentityId(ByteStreamUtils.popIntFromByteQueue(byteBuffer));
        return rVal;
    }

    public static InventoryMessage constructremoveItemFromInventoryMessage(int entityId){
        InventoryMessage rVal = new InventoryMessage(InventoryMessageType.REMOVEITEMFROMINVENTORY);
        rVal.setentityId(entityId);
        rVal.serialize();
        return rVal;
    }

    public static boolean canParseclientRequestEquipItemMessage(CircularByteBuffer byteBuffer){
        int currentStreamLength = byteBuffer.getRemaining();
        List<Byte> temporaryByteQueue = new LinkedList<Byte>();
        int equipPointIdSize = 0;
        if(currentStreamLength < 6){
            return false;
        } else {
            temporaryByteQueue.add(byteBuffer.peek(2 + 0));
            temporaryByteQueue.add(byteBuffer.peek(2 + 1));
            temporaryByteQueue.add(byteBuffer.peek(2 + 2));
            temporaryByteQueue.add(byteBuffer.peek(2 + 3));
            equipPointIdSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue);
        }
        if(currentStreamLength < 6 + equipPointIdSize){
            return false;
        }
        if(currentStreamLength < 10 + equipPointIdSize){
            return false;
        }
        return true;
    }

    public static InventoryMessage parseclientRequestEquipItemMessage(CircularByteBuffer byteBuffer){
        InventoryMessage rVal = new InventoryMessage(InventoryMessageType.CLIENTREQUESTEQUIPITEM);
        stripPacketHeader(byteBuffer);
        rVal.setequipPointId(ByteStreamUtils.popStringFromByteQueue(byteBuffer));
        rVal.setentityId(ByteStreamUtils.popIntFromByteQueue(byteBuffer));
        return rVal;
    }

    public static InventoryMessage constructclientRequestEquipItemMessage(String equipPointId,int entityId){
        InventoryMessage rVal = new InventoryMessage(InventoryMessageType.CLIENTREQUESTEQUIPITEM);
        rVal.setequipPointId(equipPointId);
        rVal.setentityId(entityId);
        rVal.serialize();
        return rVal;
    }

    public static boolean canParseserverCommandMoveItemContainerMessage(CircularByteBuffer byteBuffer){
        int currentStreamLength = byteBuffer.getRemaining();
        List<Byte> temporaryByteQueue = new LinkedList<Byte>();
        if(currentStreamLength < 6){
            return false;
        }
        if(currentStreamLength < 10){
            return false;
        }
        int equipPointIdSize = 0;
        if(currentStreamLength < 14){
            return false;
        } else {
            temporaryByteQueue.add(byteBuffer.peek(10 + 0));
            temporaryByteQueue.add(byteBuffer.peek(10 + 1));
            temporaryByteQueue.add(byteBuffer.peek(10 + 2));
            temporaryByteQueue.add(byteBuffer.peek(10 + 3));
            equipPointIdSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue);
        }
        if(currentStreamLength < 14 + equipPointIdSize){
            return false;
        }
        return true;
    }

    public static InventoryMessage parseserverCommandMoveItemContainerMessage(CircularByteBuffer byteBuffer){
        InventoryMessage rVal = new InventoryMessage(InventoryMessageType.SERVERCOMMANDMOVEITEMCONTAINER);
        stripPacketHeader(byteBuffer);
        rVal.setentityId(ByteStreamUtils.popIntFromByteQueue(byteBuffer));
        rVal.setcontainerType(ByteStreamUtils.popIntFromByteQueue(byteBuffer));
        rVal.setequipPointId(ByteStreamUtils.popStringFromByteQueue(byteBuffer));
        return rVal;
    }

    public static InventoryMessage constructserverCommandMoveItemContainerMessage(int entityId,int containerType,String equipPointId){
        InventoryMessage rVal = new InventoryMessage(InventoryMessageType.SERVERCOMMANDMOVEITEMCONTAINER);
        rVal.setentityId(entityId);
        rVal.setcontainerType(containerType);
        rVal.setequipPointId(equipPointId);
        rVal.serialize();
        return rVal;
    }

    public static boolean canParseserverCommandEquipItemMessage(CircularByteBuffer byteBuffer){
        int currentStreamLength = byteBuffer.getRemaining();
        List<Byte> temporaryByteQueue = new LinkedList<Byte>();
        if(currentStreamLength < 6){
            return false;
        }
        int equipPointIdSize = 0;
        if(currentStreamLength < 10){
            return false;
        } else {
            temporaryByteQueue.add(byteBuffer.peek(6 + 0));
            temporaryByteQueue.add(byteBuffer.peek(6 + 1));
            temporaryByteQueue.add(byteBuffer.peek(6 + 2));
            temporaryByteQueue.add(byteBuffer.peek(6 + 3));
            equipPointIdSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue);
        }
        if(currentStreamLength < 10 + equipPointIdSize){
            return false;
        }
        if(currentStreamLength < 14 + equipPointIdSize){
            return false;
        }
        int itemTemplateSize = 0;
        if(currentStreamLength < 18){
            return false;
        } else {
            temporaryByteQueue.add(byteBuffer.peek(14 + equipPointIdSize + 0));
            temporaryByteQueue.add(byteBuffer.peek(14 + equipPointIdSize + 1));
            temporaryByteQueue.add(byteBuffer.peek(14 + equipPointIdSize + 2));
            temporaryByteQueue.add(byteBuffer.peek(14 + equipPointIdSize + 3));
            itemTemplateSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue);
        }
        if(currentStreamLength < 18 + equipPointIdSize + itemTemplateSize){
            return false;
        }
        return true;
    }

    public static InventoryMessage parseserverCommandEquipItemMessage(CircularByteBuffer byteBuffer){
        InventoryMessage rVal = new InventoryMessage(InventoryMessageType.SERVERCOMMANDEQUIPITEM);
        stripPacketHeader(byteBuffer);
        rVal.setequipperId(ByteStreamUtils.popIntFromByteQueue(byteBuffer));
        rVal.setequipPointId(ByteStreamUtils.popStringFromByteQueue(byteBuffer));
        rVal.setentityId(ByteStreamUtils.popIntFromByteQueue(byteBuffer));
        rVal.setitemTemplate(ByteStreamUtils.popStringFromByteQueue(byteBuffer));
        return rVal;
    }

    public static InventoryMessage constructserverCommandEquipItemMessage(int equipperId,String equipPointId,int entityId,String itemTemplate){
        InventoryMessage rVal = new InventoryMessage(InventoryMessageType.SERVERCOMMANDEQUIPITEM);
        rVal.setequipperId(equipperId);
        rVal.setequipPointId(equipPointId);
        rVal.setentityId(entityId);
        rVal.setitemTemplate(itemTemplate);
        rVal.serialize();
        return rVal;
    }

    public static boolean canParseserverCommandUnequipItemMessage(CircularByteBuffer byteBuffer){
        int currentStreamLength = byteBuffer.getRemaining();
        List<Byte> temporaryByteQueue = new LinkedList<Byte>();
        if(currentStreamLength < 6){
            return false;
        }
        int equipPointIdSize = 0;
        if(currentStreamLength < 10){
            return false;
        } else {
            temporaryByteQueue.add(byteBuffer.peek(6 + 0));
            temporaryByteQueue.add(byteBuffer.peek(6 + 1));
            temporaryByteQueue.add(byteBuffer.peek(6 + 2));
            temporaryByteQueue.add(byteBuffer.peek(6 + 3));
            equipPointIdSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue);
        }
        if(currentStreamLength < 10 + equipPointIdSize){
            return false;
        }
        return true;
    }

    public static InventoryMessage parseserverCommandUnequipItemMessage(CircularByteBuffer byteBuffer){
        InventoryMessage rVal = new InventoryMessage(InventoryMessageType.SERVERCOMMANDUNEQUIPITEM);
        stripPacketHeader(byteBuffer);
        rVal.setequipperId(ByteStreamUtils.popIntFromByteQueue(byteBuffer));
        rVal.setequipPointId(ByteStreamUtils.popStringFromByteQueue(byteBuffer));
        return rVal;
    }

    public static InventoryMessage constructserverCommandUnequipItemMessage(int equipperId,String equipPointId){
        InventoryMessage rVal = new InventoryMessage(InventoryMessageType.SERVERCOMMANDUNEQUIPITEM);
        rVal.setequipperId(equipperId);
        rVal.setequipPointId(equipPointId);
        rVal.serialize();
        return rVal;
    }

    public static boolean canParseclientRequestUnequipItemMessage(CircularByteBuffer byteBuffer){
        int currentStreamLength = byteBuffer.getRemaining();
        List<Byte> temporaryByteQueue = new LinkedList<Byte>();
        int equipPointIdSize = 0;
        if(currentStreamLength < 6){
            return false;
        } else {
            temporaryByteQueue.add(byteBuffer.peek(2 + 0));
            temporaryByteQueue.add(byteBuffer.peek(2 + 1));
            temporaryByteQueue.add(byteBuffer.peek(2 + 2));
            temporaryByteQueue.add(byteBuffer.peek(2 + 3));
            equipPointIdSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue);
        }
        if(currentStreamLength < 6 + equipPointIdSize){
            return false;
        }
        return true;
    }

    public static InventoryMessage parseclientRequestUnequipItemMessage(CircularByteBuffer byteBuffer){
        InventoryMessage rVal = new InventoryMessage(InventoryMessageType.CLIENTREQUESTUNEQUIPITEM);
        stripPacketHeader(byteBuffer);
        rVal.setequipPointId(ByteStreamUtils.popStringFromByteQueue(byteBuffer));
        return rVal;
    }

    public static InventoryMessage constructclientRequestUnequipItemMessage(String equipPointId){
        InventoryMessage rVal = new InventoryMessage(InventoryMessageType.CLIENTREQUESTUNEQUIPITEM);
        rVal.setequipPointId(equipPointId);
        rVal.serialize();
        return rVal;
    }

    public static boolean canParseclientRequestPerformItemActionMessage(CircularByteBuffer byteBuffer){
        int currentStreamLength = byteBuffer.getRemaining();
        List<Byte> temporaryByteQueue = new LinkedList<Byte>();
        int equipPointIdSize = 0;
        if(currentStreamLength < 6){
            return false;
        } else {
            temporaryByteQueue.add(byteBuffer.peek(2 + 0));
            temporaryByteQueue.add(byteBuffer.peek(2 + 1));
            temporaryByteQueue.add(byteBuffer.peek(2 + 2));
            temporaryByteQueue.add(byteBuffer.peek(2 + 3));
            equipPointIdSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue);
        }
        if(currentStreamLength < 6 + equipPointIdSize){
            return false;
        }
        if(currentStreamLength < 10 + equipPointIdSize){
            return false;
        }
        if(currentStreamLength < 14 + equipPointIdSize){
            return false;
        }
        return true;
    }

    public static InventoryMessage parseclientRequestPerformItemActionMessage(CircularByteBuffer byteBuffer){
        InventoryMessage rVal = new InventoryMessage(InventoryMessageType.CLIENTREQUESTPERFORMITEMACTION);
        stripPacketHeader(byteBuffer);
        rVal.setequipPointId(ByteStreamUtils.popStringFromByteQueue(byteBuffer));
        rVal.setitemActionCode(ByteStreamUtils.popIntFromByteQueue(byteBuffer));
        rVal.setitemActionCodeState(ByteStreamUtils.popIntFromByteQueue(byteBuffer));
        return rVal;
    }

    public static InventoryMessage constructclientRequestPerformItemActionMessage(String equipPointId,int itemActionCode,int itemActionCodeState){
        InventoryMessage rVal = new InventoryMessage(InventoryMessageType.CLIENTREQUESTPERFORMITEMACTION);
        rVal.setequipPointId(equipPointId);
        rVal.setitemActionCode(itemActionCode);
        rVal.setitemActionCodeState(itemActionCodeState);
        rVal.serialize();
        return rVal;
    }

    @Override
    void serialize(){
        byte[] intValues = new byte[8];
        byte[] stringBytes;
        switch(this.messageType){
            case ADDITEMTOINVENTORY:
                rawBytes = new byte[2+4+4+itemTemplate.length()];
                //message header
                rawBytes[0] = TypeBytes.MESSAGE_TYPE_INVENTORY;
                //entity messaage header
                rawBytes[1] = TypeBytes.INVENTORY_MESSAGE_TYPE_ADDITEMTOINVENTORY;
                intValues = ByteStreamUtils.serializeIntToBytes(entityId);
                for(int i = 0; i < 4; i++){
                    rawBytes[2+i] = intValues[i];
                }
                intValues = ByteStreamUtils.serializeIntToBytes(itemTemplate.length());
                for(int i = 0; i < 4; i++){
                    rawBytes[6+i] = intValues[i];
                }
                stringBytes = itemTemplate.getBytes();
                for(int i = 0; i < itemTemplate.length(); i++){
                    rawBytes[10+i] = stringBytes[i];
                }
                break;
            case REMOVEITEMFROMINVENTORY:
                rawBytes = new byte[2+4];
                //message header
                rawBytes[0] = TypeBytes.MESSAGE_TYPE_INVENTORY;
                //entity messaage header
                rawBytes[1] = TypeBytes.INVENTORY_MESSAGE_TYPE_REMOVEITEMFROMINVENTORY;
                intValues = ByteStreamUtils.serializeIntToBytes(entityId);
                for(int i = 0; i < 4; i++){
                    rawBytes[2+i] = intValues[i];
                }
                break;
            case CLIENTREQUESTEQUIPITEM:
                rawBytes = new byte[2+4+equipPointId.length()+4];
                //message header
                rawBytes[0] = TypeBytes.MESSAGE_TYPE_INVENTORY;
                //entity messaage header
                rawBytes[1] = TypeBytes.INVENTORY_MESSAGE_TYPE_CLIENTREQUESTEQUIPITEM;
                intValues = ByteStreamUtils.serializeIntToBytes(equipPointId.length());
                for(int i = 0; i < 4; i++){
                    rawBytes[2+i] = intValues[i];
                }
                stringBytes = equipPointId.getBytes();
                for(int i = 0; i < equipPointId.length(); i++){
                    rawBytes[6+i] = stringBytes[i];
                }
                intValues = ByteStreamUtils.serializeIntToBytes(entityId);
                for(int i = 0; i < 4; i++){
                    rawBytes[6+equipPointId.length()+i] = intValues[i];
                }
                break;
            case SERVERCOMMANDMOVEITEMCONTAINER:
                rawBytes = new byte[2+4+4+4+equipPointId.length()];
                //message header
                rawBytes[0] = TypeBytes.MESSAGE_TYPE_INVENTORY;
                //entity messaage header
                rawBytes[1] = TypeBytes.INVENTORY_MESSAGE_TYPE_SERVERCOMMANDMOVEITEMCONTAINER;
                intValues = ByteStreamUtils.serializeIntToBytes(entityId);
                for(int i = 0; i < 4; i++){
                    rawBytes[2+i] = intValues[i];
                }
                intValues = ByteStreamUtils.serializeIntToBytes(containerType);
                for(int i = 0; i < 4; i++){
                    rawBytes[6+i] = intValues[i];
                }
                intValues = ByteStreamUtils.serializeIntToBytes(equipPointId.length());
                for(int i = 0; i < 4; i++){
                    rawBytes[10+i] = intValues[i];
                }
                stringBytes = equipPointId.getBytes();
                for(int i = 0; i < equipPointId.length(); i++){
                    rawBytes[14+i] = stringBytes[i];
                }
                break;
            case SERVERCOMMANDEQUIPITEM:
                rawBytes = new byte[2+4+4+equipPointId.length()+4+4+itemTemplate.length()];
                //message header
                rawBytes[0] = TypeBytes.MESSAGE_TYPE_INVENTORY;
                //entity messaage header
                rawBytes[1] = TypeBytes.INVENTORY_MESSAGE_TYPE_SERVERCOMMANDEQUIPITEM;
                intValues = ByteStreamUtils.serializeIntToBytes(equipperId);
                for(int i = 0; i < 4; i++){
                    rawBytes[2+i] = intValues[i];
                }
                intValues = ByteStreamUtils.serializeIntToBytes(equipPointId.length());
                for(int i = 0; i < 4; i++){
                    rawBytes[6+i] = intValues[i];
                }
                stringBytes = equipPointId.getBytes();
                for(int i = 0; i < equipPointId.length(); i++){
                    rawBytes[10+i] = stringBytes[i];
                }
                intValues = ByteStreamUtils.serializeIntToBytes(entityId);
                for(int i = 0; i < 4; i++){
                    rawBytes[10+equipPointId.length()+i] = intValues[i];
                }
                intValues = ByteStreamUtils.serializeIntToBytes(itemTemplate.length());
                for(int i = 0; i < 4; i++){
                    rawBytes[14+equipPointId.length()+i] = intValues[i];
                }
                stringBytes = itemTemplate.getBytes();
                for(int i = 0; i < itemTemplate.length(); i++){
                    rawBytes[18+equipPointId.length()+i] = stringBytes[i];
                }
                break;
            case SERVERCOMMANDUNEQUIPITEM:
                rawBytes = new byte[2+4+4+equipPointId.length()];
                //message header
                rawBytes[0] = TypeBytes.MESSAGE_TYPE_INVENTORY;
                //entity messaage header
                rawBytes[1] = TypeBytes.INVENTORY_MESSAGE_TYPE_SERVERCOMMANDUNEQUIPITEM;
                intValues = ByteStreamUtils.serializeIntToBytes(equipperId);
                for(int i = 0; i < 4; i++){
                    rawBytes[2+i] = intValues[i];
                }
                intValues = ByteStreamUtils.serializeIntToBytes(equipPointId.length());
                for(int i = 0; i < 4; i++){
                    rawBytes[6+i] = intValues[i];
                }
                stringBytes = equipPointId.getBytes();
                for(int i = 0; i < equipPointId.length(); i++){
                    rawBytes[10+i] = stringBytes[i];
                }
                break;
            case CLIENTREQUESTUNEQUIPITEM:
                rawBytes = new byte[2+4+equipPointId.length()];
                //message header
                rawBytes[0] = TypeBytes.MESSAGE_TYPE_INVENTORY;
                //entity messaage header
                rawBytes[1] = TypeBytes.INVENTORY_MESSAGE_TYPE_CLIENTREQUESTUNEQUIPITEM;
                intValues = ByteStreamUtils.serializeIntToBytes(equipPointId.length());
                for(int i = 0; i < 4; i++){
                    rawBytes[2+i] = intValues[i];
                }
                stringBytes = equipPointId.getBytes();
                for(int i = 0; i < equipPointId.length(); i++){
                    rawBytes[6+i] = stringBytes[i];
                }
                break;
            case CLIENTREQUESTPERFORMITEMACTION:
                rawBytes = new byte[2+4+equipPointId.length()+4+4];
                //message header
                rawBytes[0] = TypeBytes.MESSAGE_TYPE_INVENTORY;
                //entity messaage header
                rawBytes[1] = TypeBytes.INVENTORY_MESSAGE_TYPE_CLIENTREQUESTPERFORMITEMACTION;
                intValues = ByteStreamUtils.serializeIntToBytes(equipPointId.length());
                for(int i = 0; i < 4; i++){
                    rawBytes[2+i] = intValues[i];
                }
                stringBytes = equipPointId.getBytes();
                for(int i = 0; i < equipPointId.length(); i++){
                    rawBytes[6+i] = stringBytes[i];
                }
                intValues = ByteStreamUtils.serializeIntToBytes(itemActionCode);
                for(int i = 0; i < 4; i++){
                    rawBytes[6+equipPointId.length()+i] = intValues[i];
                }
                intValues = ByteStreamUtils.serializeIntToBytes(itemActionCodeState);
                for(int i = 0; i < 4; i++){
                    rawBytes[10+equipPointId.length()+i] = intValues[i];
                }
                break;
        }
        serialized = true;
    }

}
