Beispiel #1
0
        /// <summary>
        /// 拷贝创建描述信息
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public static fieldDescriptor copyCreateDescriptor(fieldDescriptor other)
        {
            if (other == null)
            {
                return(null);
            }

            return(createDescriptor(other.modifier, other.typeCode, other.name, other.nestedTypeName));
        }
Beispiel #2
0
        ////////////////////////////////////////////////////////

        /// <summary>
        /// 创建字段信息
        /// </summary>
        public static fieldDataInfo createFieldData(int number, fieldDescriptor descriptor)
        {
            if (number <= 0 || descriptor == null)
            {
                return(null);
            }

            return(new fieldDataInfo(number, descriptor));
        }
Beispiel #3
0
        /// <summary>
        /// 读取lua消息
        /// </summary>
        internal static luaMessage readLuaMessage(object idMsg, LuaTable luaMsgTbl)
        {
            if (luaMsgTbl == null)
            {
                return(null);
            }

            luaMessage msg = (luaMessage)luaMessageCache.createTypeInstance(idMsg);

            if (msg == null)
            {
                return(null);
            }

            //按照索引顺序读取lua表中对应字段的值
            int           count     = msg.fieldsCount();
            fieldDataInfo fieldData = null;

            for (int i = 1; i <= count; i++)
            {
                fieldData = (fieldDataInfo)msg[i];
                if (fieldData == null)
                {
                    continue;
                }

                //检查lua表中对应字段的值
                string name = fieldData.descriptor.name;
                if (luaMsgTbl[name] == null)
                {
                    continue;
                }

                //创建值字段
                if (!fieldData.appendValue())
                {
                    continue;
                }

                fieldDescriptor des = fieldData.descriptor;
                if (des.isRepeated())
                {
                    LuaTable repeatedTbl = (LuaTable)luaMsgTbl[name];
                    for (int j = 1; j <= repeatedTbl.length(); j++)
                    {
                        object subValue = luaType2CType(des.typeCode, repeatedTbl[j]);
                        if (subValue == null)
                        {
                            continue;
                        }

                        //嵌入类型
                        if (des.haveNestedType())
                        {
                            object subMsg = readLuaMessage(des.nestedTypeName, (LuaTable)subValue);
                            if (subMsg != null)
                            {
                                fieldData.Value.addChild(subMsg);
                            }
                        }
                        else
                        {
                            fieldData.Value.addChild(subValue);
                        }
                    }
                }
                else
                {
                    object value = luaType2CType(des.typeCode, luaMsgTbl[name]);
                    if (value == null)
                    {
                        continue;
                    }

                    //嵌入类型
                    if (des.haveNestedType())
                    {
                        fieldData.Value.valueL = readLuaMessage(des.nestedTypeName, (LuaTable)value);
                    }
                    else
                    {
                        fieldData.Value.valueL = value;
                    }
                }
            }

            return(msg);
        }
Beispiel #4
0
 /// <summary>
 /// 构造函数,只需传入描述信息
 /// </summary>
 private fieldDataInfo(int number, fieldDescriptor descriptor)
 {
     _number    = number;
     _decriptor = descriptor;
 }