예제 #1
0
        Dictionary <string, object> AnalysisData(string MessageType, byte[] bytes)
        {
            //Debug.Log("MessageType:" + MessageType + "AnalysisData: " +  BitConverter.ToString(bytes));

            string fieldName  = "";
            string customType = "";
            int    fieldType  = 0;
            int    repeatType = 0;

            try
            {
                Dictionary <string, object> data = new Dictionary <string, object>();
                ByteArray ba = new ByteArray();

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

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

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

                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] = ReadInt32(ba);
                        }
                    }
                    else if (fieldType == TYPE_int16)
                    {
                        if (repeatType == RT_repeated)
                        {
                            data[fieldName] = ReadShortList(ba);
                        }
                        else
                        {
                            data[fieldName] = ReadInt16(ba);
                        }
                    }
                    else if (fieldType == TYPE_int8)
                    {
                        if (repeatType == RT_repeated)
                        {
                            data[fieldName] = ReadInt8List(ba);
                        }
                        else
                        {
                            data[fieldName] = ReadInt8(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());
            }
        }