Exemplo n.º 1
0
    public override void SendMessage(string MessageType, Dictionary <string, object> data)
    {
        ByteArray msg = HeapObjectPoolTool <ByteArray> .GetHeapObject();

        msg.clear();

        List <byte> message = GetSendByte(MessageType, data);

        int len    = 3 + message.Count;
        int method = GetMethodIndex(MessageType);

        msg.WriteShort(len);
        msg.WriteByte((byte)(method / 100));
        msg.WriteShort(method);

        if (message != null)
        {
            msg.bytes.AddRange(message);
        }
        else
        {
            msg.WriteInt(0);
        }

        Send(msg.Buffer);
    }
Exemplo n.º 2
0
    //public static T GetEvent<T>() where T : IInputEventBase, new()
    //{
    //    return InputOperationEventProxy.GetEvent<T>();
    //}

    public static T GetEvent <T>(string eventKey) where T : IInputEventBase, new()
    {
        T tmp = HeapObjectPoolTool <T> .GetHeapObject();

        tmp.EventKey = eventKey;

        return(tmp);
    }
    public static Dictionary <string, object> SafeGetSODict()
    {
        Dictionary <string, object> dict = HeapObjectPoolTool <Dictionary <string, object> > .GetHeapObject();

        dict.Clear();

        return(dict);
    }
    static T GetUIEvent <T>(string UIName, string ComponentName, string parm) where T : InputUIEventBase, new()
    {
        T msg = HeapObjectPoolTool <T> .GetHeapObject();

        msg.Reset();
        msg.m_name     = UIName;
        msg.m_compName = ComponentName;
        msg.m_pram     = parm;

        return(msg);
    }
Exemplo n.º 5
0
    private List <Dictionary <string, object> > ReadDictionaryList(string str, ByteArray ba)
    {
        List <Dictionary <string, object> > stbl = HeapObjectPoolTool <List <Dictionary <string, object> > > .GetHeapObject();

        stbl.Clear();
        int len1 = ba.ReadShort();

        ba.ReadInt();

        for (int i = 0; i < len1; i++)
        {
            stbl.Add(ReadDictionary(str, ba));
        }
        return(stbl);
    }
Exemplo n.º 6
0
    private List <double> ReadDoubleList(ByteArray ba)
    {
        List <double> tbl = HeapObjectPoolTool <List <double> > .GetHeapObject();

        tbl.Clear();

        int len1 = ba.ReadShort();

        ba.ReadInt();

        for (int i = 0; i < len1; i++)
        {
            tbl.Add(ReadDouble(ba));
        }
        return(tbl);
    }
    private List <int> ReadIntList(ByteArray ba)
    {
        List <int> tbl = HeapObjectPoolTool <List <int> > .GetHeapObject();

        tbl.Clear();

        int len1 = ba.ReadShort();

        ba.ReadInt();

        for (int i = 0; i < len1; i++)
        {
            int tem_o_read_int = ReadInt(ba);
            tbl.Add(tem_o_read_int);
        }

        return(tbl);
    }
    //解包
    private void ReceiveDataLoad(byte[] bytes)
    {
        try
        {
            ByteArray ba = HeapObjectPoolTool <ByteArray> .GetHeapObject();

            //用于做数据处理,加解密,或者压缩于解压缩
            ba.clear();
            ba.Add(bytes);

            NetWorkMessage msg = Analysis(ba);
            m_messageCallBack(msg);
        }
        catch (Exception e)
        {
            Debug.LogError(e.ToString());
        }
    }
Exemplo n.º 9
0
    private List <byte> GetCustomTypeByte(string customType, Dictionary <string, object> data)
    {
        string fieldName  = null;
        int    fieldType  = 0;
        int    repeatType = 0;

        try
        {
            ByteArray Bytes = HeapObjectPoolTool <ByteArray> .GetHeapObject();

            Bytes.clear();

            if (!m_protocolInfo.ContainsKey(customType))
            {
                throw new Exception("ProtocolInfo NOT Exist ->" + customType + "<-");
            }

            List <Dictionary <string, object> > tableInfo = m_protocolInfo[customType];

            for (int i = 0; i < tableInfo.Count; i++)
            {
                Dictionary <string, object> currentField = tableInfo[i];
                fieldType  = (int)currentField["type"];
                fieldName  = (string)currentField["name"];
                repeatType = (int)currentField["spl"];

                if (fieldType == TYPE_string)
                {
                    if (data.ContainsKey(fieldName))
                    {
                        if (repeatType == RT_equired)
                        {
                            Bytes.WriteString((string)data[fieldName]);
                        }
                        else
                        {
                            List <object> list = (List <object>)data[fieldName];

                            Bytes.WriteShort(list.Count);
                            Bytes.WriteInt(GetStringListLength(list));
                            for (int i2 = 0; i2 < list.Count; i2++)
                            {
                                Bytes.WriteString((string)list[i2]);
                            }
                        }
                    }
                    else
                    {
                        Bytes.WriteShort(0);
                    }
                }
                else if (fieldType == TYPE_bool)
                {
                    if (data.ContainsKey(fieldName))
                    {
                        if (repeatType == RT_equired)
                        {
                            Bytes.WriteBoolean((bool)data[fieldName]);
                        }
                        else
                        {
                            List <object> tb = (List <object>)data[fieldName];
                            Bytes.WriteShort(tb.Count);
                            Bytes.WriteInt(tb.Count);
                            for (int i2 = 0; i2 < tb.Count; i2++)
                            {
                                Bytes.WriteBoolean((bool)tb[i2]);
                            }
                        }
                    }
                }
                else if (fieldType == TYPE_double)
                {
                    if (data.ContainsKey(fieldName))
                    {
                        if (repeatType == RT_equired)
                        {
                            Bytes.WriteDouble((float)data[fieldName]);
                        }
                        else
                        {
                            List <object> tb = (List <object>)data[fieldName];
                            Bytes.WriteShort(tb.Count);
                            Bytes.WriteInt(tb.Count * 8);
                            for (int j = 0; j < tb.Count; j++)
                            {
                                Bytes.WriteDouble((float)tb[j]);
                            }
                        }
                    }
                }
                else if (fieldType == TYPE_int32)
                {
                    if (data.ContainsKey(fieldName))
                    {
                        if (repeatType == RT_equired)
                        {
                            Bytes.WriteInt(int.Parse(data[fieldName].ToString()));
                        }
                        else
                        {
                            List <object> tb = (List <object>)data[fieldName];
                            Bytes.WriteShort(tb.Count);
                            Bytes.WriteInt(tb.Count * 4);
                            for (int i2 = 0; i2 < tb.Count; i2++)
                            {
                                Bytes.WriteInt(int.Parse(tb[i2].ToString()));
                            }
                        }
                    }
                }
                else
                {
                    if (data.ContainsKey(fieldName))
                    {
                        if (repeatType == RT_equired)
                        {
                            customType = (string)currentField["vp"];
                            Bytes.bytes.AddRange(GetSendByte(customType, (Dictionary <string, object>)data[fieldName]));
                        }
                        else
                        {
                            List <object> tb = (List <object>)data[fieldName];

                            Bytes.WriteShort(tb.Count);
                            //这里会修改m_arrayCatch的值,下面就可以直接使用
                            Bytes.WriteInt(GetCustomListLength(customType, tb));

                            for (int j = 0; j < m_arrayCatch.Count; j++)
                            {
                                List <byte> tempb = m_arrayCatch[j];
                                Bytes.WriteInt(tempb.Count);
                                Bytes.bytes.AddRange(tempb);
                            }
                        }
                    }
                }
            }

            return(Bytes.bytes);
        }
        catch (Exception e)
        {
            throw new Exception(@"GetCustomTypeByte Excepiton CustomType is ->" + customType
                                + "<-\nFieldName:->" + fieldName
                                + "<-\nFieldType:->" + GetFieldType(fieldType)
                                + "<-\nRepeatType:->" + GetRepeatType(repeatType)
                                + "<-\nCustomType:->" + customType
                                + "<-\n" + e.ToString());
        }
    }
Exemplo n.º 10
0
    Dictionary <string, object> AnalysisData(string MessageType, byte[] bytes)
    {
        string fieldName  = "";
        string customType = "";
        int    fieldType  = 0;
        int    repeatType = 0;

        try
        {
            Dictionary <string, object> data = HeapObjectPool.GetSODict();
            ByteArray ba = HeapObjectPoolTool <ByteArray> .GetHeapObject();

            ba.clear();
            ba.Add(bytes);

            string messageTypeTemp = "m_" + MessageType + "_c";
            if (!m_protocolInfo.ContainsKey(messageTypeTemp))
            {
                throw new Exception("ProtocolInfo NOT Exist ->" + messageTypeTemp + "<-");
            }

            List <Dictionary <string, object> > tableInfo = m_protocolInfo["m_" + MessageType + "_c"];

            for (int i = 0; i < tableInfo.Count; i++)
            {
                fieldType  = (int)tableInfo[i]["type"];
                repeatType = (int)tableInfo[i]["spl"];
                fieldName  = (string)tableInfo[i]["name"];

                if (fieldType == TYPE_string)
                {
                    if (repeatType == RT_repeated)
                    {
                        data[fieldName] = ReadStringList(ba);
                    }
                    else
                    {
                        data[fieldName] = ReadString(ba);
                    }
                }
                else if (fieldType == TYPE_bool)
                {
                    if (repeatType == RT_repeated)
                    {
                        data[fieldName] = ReadBoolList(ba);
                    }
                    else
                    {
                        data[fieldName] = ReadBool(ba);
                    }
                }
                else if (fieldType == TYPE_double)
                {
                    if (repeatType == RT_repeated)
                    {
                        data[fieldName] = ReadDoubleList(ba);
                    }
                    else
                    {
                        data[fieldName] = ReadDouble(ba);
                    }
                }
                else if (fieldType == TYPE_int32)
                {
                    if (repeatType == RT_repeated)
                    {
                        data[fieldName] = ReadIntList(ba);
                    }
                    else
                    {
                        data[fieldName] = ReadInt(ba);
                    }
                }
                else
                {
                    customType = (string)tableInfo[i]["vp"];

                    if (repeatType == RT_repeated)
                    {
                        data[fieldName] = ReadDictionaryList(customType, ba);
                    }
                    else
                    {
                        data[fieldName] = ReadDictionary(customType, ba);
                    }
                }
            }

            return(data);
        }
        catch (Exception e)
        {
            throw new Exception(@"AnalysisData Excepiton Data is ->" + MessageType
                                + "<-\nFieldName:->" + fieldName
                                + "<-\nFieldType:->" + GetFieldType(fieldType)
                                + "<-\nRepeatType:->" + GetRepeatType(repeatType)
                                + "<-\nCustomType:->" + customType
                                + "<-\n" + e.ToString());
        }
    }