示例#1
0
        public void MergeFrom(ref object value, IStream ms)
        {
            if (ms.ReadByte() == 0)
            {
                value = null;
                return;
            }

            int count = ms.ReadVarInt32();
            var dic   = (IDictionary)value;

            if (value == null)
            {
                value = System.Activator.CreateInstance(type, count);
                dic   = (IDictionary)value;
            }

            for (int i = 0; i < count; ++i)
            {
                object keyValue   = IL.Help.Create(keyType);
                object valueValue = IL.Help.Create(valueType);

                RLStream.MergeFrom(keyTypeSerialize, ms, ref keyValue);
                RLStream.MergeFrom(valueTypeSerialize, ms, ref valueValue);

                dic[keyValue] = valueValue;
            }
        }
示例#2
0
        void ITypeSerialize.MergeFrom(ref object value, IStream stream)
        {
            byte flag = stream.ReadByte();

            if (flag == 0)
            {
                value = null;
                return;
            }

            byte flagType = stream.ReadByte();
            int  lenght   = stream.ReadVarInt32();

            bool isTypeTrue = flagType == elementTypeSerialize.typeFlag; // 类型是否一致
            var  array      = value as IList;

            if (isTypeTrue && (array == null || array.Count != lenght))
            {
                array = Create(lenght);
                value = array;
            }

            for (int i = 0; i < lenght; ++i)
            {
                int count  = RLStream.ReadLength(stream);
                int endpos = stream.WritePos;
                stream.WritePos = stream.ReadPos + count;
                try
                {
                    if (isTypeTrue)
                    {
                        object v = array[i];
                        elementTypeSerialize.MergeFrom(ref v, stream);
                        array[i] = v;
                    }
                    else
                    {
#if UNITY_EDITOR
                        if (stream.ReadSize != 0)
                        {
                            L.LogErrorFormat("IListAnyType stream.ReadSize != 0");
                        }
#endif
                        stream.ReadPos += count;
                    }
                }
                catch (System.Exception ex)
                {
                    L.LogException(ex);
                }
                finally
                {
                    stream.WritePos = endpos;
                }
            }
        }
示例#3
0
        void ITypeSerialize.MergeFrom(ref object value, IStream stream)
        {
            byte flag = stream.ReadByte();

            if (flag == 0)
            {
                value = null;
                return;
            }

            byte flagType = stream.ReadByte();
            int  lenght   = stream.ReadVarInt32();

            bool isTypeTrue = flagType == elementTypeSerialize.typeFlag; // 类型是否一致
            var  array      = value as IList;

            if (isTypeTrue && (array == null || array.Count != lenght))
            {
                array = Create(lenght);
                value = array;
            }

            if (isTypeTrue)
            {
                for (int i = 0; i < lenght; ++i)
                {
                    object v = array[i];
                    RLStream.MergeFrom(elementTypeSerialize, stream, ref v);
                    try
                    {
                        array[i] = v;
                    }
                    catch (System.Exception ex)
                    {
                        L.LogException(ex);
                    }
                }
            }
            else
            {
                for (int i = 0; i < lenght; ++i)
                {
                    RLStream.Next(stream);
                }
            }
        }
示例#4
0
        public void MergeFrom(ref object value, IStream stream)
        {
            byte flag = stream.ReadByte();

            if (flag == 0)
            {
                value = null;
                return;
            }

            if (value == null)
            {
                value = IL.Help.Create(type);
            }

            if (flag == 2)
            {
                return;
            }

            do
            {
                byte typeFlag  = stream.ReadByte();
                var  fieldName = stream.ReadString();
                var  length    = RLStream.ReadLength(stream);

                int endPos = stream.WritePos;
                stream.WritePos = stream.ReadPos + length;
                try
                {
                    var            fieldInfo = FindFieldInfo(fieldName);
                    ITypeSerialize bs;

                    if (fieldInfo == null)
                    {
                        //L.LogFormat("type:{0} field:{1} typeFlag:{2} 字段不存在!", IL.Help.GetInstanceType(value).FullName, fieldName, typeFlag);
                        stream.ReadPos += length;
                    }
                    else if ((bs = BinarySerializable.GetByFieldInfo(fieldInfo)).typeFlag != typeFlag)
                    {
                        // 类型与之前的有变化了
                        //L.LogFormat("type:{0} field:{1} typeFlag {2}->{3} 有变化!", IL.Help.GetInstanceType(value).FullName, fieldName, typeFlag, bs.typeFlag);
                        stream.ReadPos += length;
                    }
                    else
                    {
                        object cv = fieldInfo.GetValue(value);
                        bs.MergeFrom(ref cv, stream);
                        if (typeFlag == TypeFlags.unityObjectType)
                        {
                            cv = UnityObjectSerialize.To((UnityEngine.Object)cv, fieldInfo.FieldType);
                        }

                        fieldInfo.SetValue(value, cv);
                    }
                }
                catch (System.Exception ex)
                {
                    wxb.L.LogException(ex);
                }
                finally
                {
#if UNITY_EDITOR
                    if (stream.ReadSize != 0)
                    {
                        wxb.L.LogErrorFormat("type:{0} fieldName:{1} length:{2}", type.Name, fieldName, length);
                    }
#endif
                    stream.WritePos = endPos;
                }
            }while (stream.ReadSize != 0);
        }