Пример #1
0
        /// <summary>
        /// 真实类型
        /// </summary>
        /// <param name="deSerializer">二进制数据反序列化</param>
        /// <param name="value">数据对象</param>
        private static void realType(DeSerializer deSerializer, ref valueType value)
        {
            RemoteType remoteType = default(RemoteType);

            TypeDeSerializer <RemoteType> .StructDeSerialize(deSerializer, ref remoteType);

            if (deSerializer.State == DeSerializeState.Success)
            {
                Type type;
                if (remoteType.TryGet(out type))
                {
                    if (value == null || type.IsValueType)
                    {
                        value = (valueType)DeSerializeMethodCache.GetRealDeSerializer(type)(deSerializer, value);
                    }
                    else
                    {
                        DeSerializeMethodCache.GetRealDeSerializer(type)(deSerializer, value);
                    }
                }
                else
                {
                    deSerializer.State = DeSerializeState.RemoteTypeError;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 真实类型
        /// </summary>
        /// <param name="deSerializer">二进制数据反序列化</param>
        /// <param name="value">数据对象</param>
        private static void realType(DeSerializer deSerializer, ref valueType value)
        {
            RemoteType remoteType = default(RemoteType);

            TypeDeSerializer <RemoteType> .GetDeSerializer(deSerializer.GlobalVersion).MemberDeSerialize(deSerializer, ref remoteType);

            if (deSerializer.State == DeSerializeState.Success)
            {
                Type type;
                if (remoteType.TryGet(out type))
                {
                    if (value == null || type.IsValueType)
                    {
                        //value = (valueType)DeSerializeMethodCache.GetRealDeSerializer(type)(deSerializer, value);
                        value = (valueType)GenericType.Get(type).BinaryDeSerializeRealTypeObjectDelegate(deSerializer, value);
                    }
                    //else DeSerializeMethodCache.GetRealDeSerializer(type)(deSerializer, value);
                    else
                    {
                        GenericType.Get(type).BinaryDeSerializeRealTypeObjectDelegate(deSerializer, value);
                    }
                }
                else
                {
                    deSerializer.State = DeSerializeState.RemoteTypeError;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 创建二进制数据反序列化
        /// </summary>
        /// <param name="attribute"></param>
        /// <returns></returns>
        internal TypeDeSerializer <valueType> CreateOnly(BinarySerializeAttribute attribute)
        {
            DeSerializeVersionField[] fieldArray = this.fields;
            LeftArray <FieldSize>     fixedFields = new LeftArray <FieldSize>(fieldArray.Length - noSerializeMemberCount), fields = new LeftArray <FieldSize>(fieldArray.Length - noSerializeMemberCount);
            LeftArray <AutoCSer.Metadata.FieldIndex> jsonFields = new LeftArray <AutoCSer.Metadata.FieldIndex>(0);
            int fixedSize = 0;

            AutoCSer.Algorithm.QuickSort.Sort(fieldArray, DeSerializeVersionField.MemberNameSort, 0, fieldArray.Length);
            if (attribute.GetIsMemberMap)
            {
                int memberIndex = 0;
                LeftArray <DeSerializeVersionField> newFields = new LeftArray <DeSerializeVersionField>(fieldArray.Length);
                foreach (DeSerializeVersionField field in fieldArray)
                {
                    if (field.Attribute != null)
                    {
                        if (field.Field.MemberIndex == memberIndex)
                        {
                            newFields.Add(field);
                        }
                        else
                        {
                            newFields.Add(field.Copy(memberIndex));
                        }
                    }
                    ++memberIndex;
                }
                fieldArray = newFields.ToArray();
            }
            else if (noSerializeMemberCount != 0)
            {
                fieldArray = fieldArray.getFindArray(value => value.Attribute != null);
            }
            foreach (DeSerializeVersionField field in fieldArray)
            {
                BinarySerializeMemberAttribute memberAttribute = field.Attribute;
                if (memberAttribute.GetIsJson)
                {
                    jsonFields.Add(field.Field);
                }
                else
                {
                    FieldSize value = new FieldSize(field.Field);
                    if (value.FixedSize == 0)
                    {
                        fields.Add(value);
                    }
                    else
                    {
                        fixedFields.Add(value);
                        fixedSize += value.FixedSize;
                    }
                }
            }
            int memberCountVerify;
            Fields <FieldSize> fieldSizes = new Fields <FieldSize>(ref fixedFields, ref fields, ref jsonFields, fixedSize, attribute.GetIsJson, out memberCountVerify);

            return(DeSerializer = new TypeDeSerializer <valueType>(GlobalVersion, ref fieldSizes, memberCountVerify));
        }
        //[AutoCSer.IOS.Preserve(Conditional = true)]
        internal void subArrayDeSerialize <valueType>(ref SubArray <valueType> value)
        {
            valueType[] array = null;
            isReferenceArray = false;
            TypeDeSerializer <valueType[]> .DefaultDeSerializer(this, ref array);

            value.Set(array, 0, array.Length);
        }
Пример #5
0
 /// <summary>
 /// 二进制数据反序列化版本字段信息
 /// </summary>
 /// <param name="globalVersion">全局版本编号</param>
 /// <param name="fields">字段集合</param>
 /// <param name="removeMemberCount">被删除成员数量</param>
 /// <param name="noSerializeMemberCount">非序列化成员数量</param>
 internal DeSerializeVersionFields(uint globalVersion, DeSerializeVersionField[] fields, uint removeMemberCount, int noSerializeMemberCount)
 {
     GlobalVersion               = globalVersion;
     this.fields                 = fields;
     this.removeMemberCount      = removeMemberCount;
     this.noSerializeMemberCount = noSerializeMemberCount;
     CreateLock   = null;
     DeSerializer = null;
 }
        /// <summary>
        /// 反序列化
        /// </summary>
        /// <typeparam name="valueType">数据类型</typeparam>
        /// <param name="data">数据</param>
        /// <param name="value">目标对象</param>
        /// <returns>是否成功</returns>
        internal bool DeSerializeTcpServer <valueType>(ref SubArray <byte> data, ref valueType value)
        {
            if (data.Length >= sizeof(int) * 3 && (data.Length & 3) == 0)
            {
                fixed(byte *dataFixed = (Buffer = data.Array))
                {
                    start = dataFixed + (bufferIndex = data.Start);
                    int length = data.Length - sizeof(int);

                    End = start + length;
                    if (((uint)(*(int *)End ^ length) | ((*(uint *)start & SerializeConfig.HeaderMapAndValue) ^ SerializeConfig.HeaderMapValue)) == 0)
                    {
                        //MemberMap = null;
                        getGlobalVersion();
                        if (isReferenceMember == TypeDeSerializer <valueType> .IsReferenceMember)
                        {
                            if (points != null)
                            {
                                points.Clear();
                            }
                        }
                        else
                        {
                            if (isReferenceMember)
                            {
                                isReferenceMember = false;
                            }
                            else
                            {
                                isReferenceMember = true;
                                if (points == null)
                                {
                                    points = ReusableDictionary.CreateInt <object>();
                                }
                                else
                                {
                                    points.Clear();
                                }
                            }
                        }
                        isReferenceArray = true;
                        State            = DeSerializeState.Success;
                        TypeDeSerializer <valueType> .DeSerializeTcpServer(this, ref value);

                        return(State == DeSerializeState.Success && Read == End);
                    }
                }
            }
            return(false);
        }
Пример #7
0
        private void deSerialize(ref Type value)
        {
            if (CheckPoint(ref value))
            {
                RemoteType remoteType = default(RemoteType);
                int        point      = (int)(start - Read);
                TypeDeSerializer <RemoteType> .DeSerialize(this, ref remoteType);

                if (State == DeSerializeState.Success)
                {
                    if (remoteType.TryGet(out value))
                    {
                        if (isReferenceMember)
                            points.Add(point, value); }
                    }
                    else
                    {
                        State = DeSerializeState.ErrorType;
                    }
                }
            }