Esempio n. 1
0
        /// <summary>
        /// 数组解析
        /// </summary>
        /// <param name="deSerializer">XML解析器</param>
        /// <param name="values">目标数据</param>
        /// <returns>数据数量,-1表示失败</returns>
        internal static int ArrayIndex(XmlDeSerializer deSerializer, ref T[] values)
        {
            if (values == null)
            {
                values = EmptyArray <T> .Array;
            }
            string arrayItemName = deSerializer.ArrayItemName;

            AutoCSer.Memory.Pointer name = default(AutoCSer.Memory.Pointer);
            int  index    = 0;
            byte isTagEnd = 0;

            fixed(char *itemFixed = arrayItemName)
            {
                do
                {
                    if ((name.Data = deSerializer.GetName(ref name.ByteSize, ref isTagEnd)) == null)
                    {
                        break;
                    }
                    if (isTagEnd == 0)
                    {
                        if (arrayItemName.Length != name.ByteSize || !AutoCSer.Memory.Common.SimpleEqualNotNull((byte *)itemFixed, name.Byte, name.ByteSize << 1))
                        {
                            deSerializer.State = DeSerializeState.NotArrayItem;
                            return(-1);
                        }
                        if (index == values.Length)
                        {
                            T value = default(T);
                            if (deSerializer.IsArrayItem(itemFixed, arrayItemName.Length) != 0)
                            {
                                DeSerialize(deSerializer, ref value);
                                if (deSerializer.State != DeSerializeState.Success)
                                {
                                    return(-1);
                                }
                                if (deSerializer.CheckNameEnd(itemFixed, name.ByteSize) == 0)
                                {
                                    break;
                                }
                            }
                            values          = values.copyNew(index == 0 ? deSerializer.Config.NewArraySize : (index << 1));
                            values[index++] = value;
                        }
                        else
                        {
                            if (deSerializer.IsArrayItem(itemFixed, arrayItemName.Length) != 0)
                            {
                                DeSerialize(deSerializer, ref values[index]);
                                if (deSerializer.State != DeSerializeState.Success)
                                {
                                    return(-1);
                                }
                                if (deSerializer.CheckNameEnd(itemFixed, name.ByteSize) == 0)
                                {
                                    break;
                                }
                            }
                            ++index;
                        }
                    }
                    else
                    {
                        if (index == values.Length)
                        {
                            values = values.copyNew(index == 0 ? deSerializer.Config.NewArraySize : (index << 1));
                        }
                        values[index++] = default(T);
                    }
                }while (true);
            }

            return(deSerializer.State == DeSerializeState.Success ? index : -1);
        }
Esempio n. 2
0
        /// <summary>
        /// 数据成员解析
        /// </summary>
        /// <param name="deSerializer">XML解析器</param>
        /// <param name="value">目标数据</param>
        internal static void DeSerializeMembers(XmlDeSerializer deSerializer, ref T value)
        {
            byte *            names     = memberNames.Byte;
            DeSerializeConfig config    = deSerializer.Config;
            MemberMap         memberMap = deSerializer.MemberMap;
            int index = 0;

            if (memberMap == null)
            {
                while (deSerializer.IsName(names, ref index))
                {
                    if (index == -1)
                    {
                        return;
                    }
                    memberDeSerializers[index].Call(deSerializer, ref value);
                    if (deSerializer.State != DeSerializeState.Success)
                    {
                        return;
                    }
                    if (deSerializer.IsNameEnd(names) == 0)
                    {
                        if (deSerializer.CheckNameEnd((char *)(names + (sizeof(short) + sizeof(char))), (*(short *)names >> 1) - 2) == 0)
                        {
                            return;
                        }
                        break;
                    }
                    ++index;
                    names += *(short *)names + sizeof(short);
                }
                AutoCSer.StateSearcher.CharSearcher searcher = new AutoCSer.StateSearcher.CharSearcher(memberSearcher);
                AutoCSer.Memory.Pointer             name     = default(AutoCSer.Memory.Pointer);
                byte isTagEnd = 0;
                if (onUnknownName == null)
                {
                    do
                    {
                        if ((name.Data = deSerializer.GetName(ref name.ByteSize, ref isTagEnd)) == null)
                        {
                            return;
                        }
                        if (isTagEnd == 0)
                        {
                            if ((index = searcher.UnsafeSearch(name.Char, name.ByteSize)) == -1)
                            {
                                if (deSerializer.IgnoreValue() == 0)
                                {
                                    return;
                                }
                            }
                            else if (memberDeSerializers[index].Call(deSerializer, ref value) == 0)
                            {
                                return;
                            }
                            if (deSerializer.CheckNameEnd(name.Char, name.ByteSize) == 0)
                            {
                                return;
                            }
                        }
                    }while (true);
                }
                else
                {
                    do
                    {
                        if ((name.Data = deSerializer.GetName(ref name.ByteSize, ref isTagEnd)) == null)
                        {
                            return;
                        }
                        if (isTagEnd == 0)
                        {
                            if ((index = searcher.UnsafeSearch(name.Char, name.ByteSize)) == -1)
                            {
                                name.ByteSize <<= 1;
                                if (onUnknownName(deSerializer, ref value, ref name))
                                {
                                    if (deSerializer.State != DeSerializeState.Success)
                                    {
                                        return;
                                    }
                                }
                                else
                                {
                                    if (deSerializer.State == DeSerializeState.Success)
                                    {
                                        deSerializer.State = DeSerializeState.UnknownNameError;
                                    }
                                    return;
                                }
                            }
                            else if (memberDeSerializers[index].Call(deSerializer, ref value) == 0)
                            {
                                return;
                            }
                            if (deSerializer.CheckNameEnd(name.Char, name.ByteSize) == 0)
                            {
                                return;
                            }
                        }
                    }while (true);
                }
            }
            else if (object.ReferenceEquals(memberMap.Type, MemberMap <T> .MemberMapType))
            {
                memberMap.Empty();
                deSerializer.MemberMap = null;
                while (deSerializer.IsName(names, ref index))
                {
                    if (index == -1)
                    {
                        return;
                    }
                    memberDeSerializers[index].Call(deSerializer, memberMap, ref value);
                    if (deSerializer.State != DeSerializeState.Success)
                    {
                        return;
                    }
                    if (deSerializer.IsNameEnd(names) == 0)
                    {
                        if (deSerializer.CheckNameEnd((char *)(names + (sizeof(short) + sizeof(char))), (*(short *)names >> 1) - 2) == 0)
                        {
                            return;
                        }
                        break;
                    }
                    ++index;
                    names += *(short *)names + sizeof(short);
                }
                AutoCSer.StateSearcher.CharSearcher searcher = new AutoCSer.StateSearcher.CharSearcher(memberSearcher);
                AutoCSer.Memory.Pointer             name     = default(AutoCSer.Memory.Pointer);
                byte isTagEnd = 0;
                try
                {
                    if (onUnknownName == null)
                    {
                        do
                        {
                            if ((name.Data = deSerializer.GetName(ref name.ByteSize, ref isTagEnd)) == null)
                            {
                                return;
                            }
                            if (isTagEnd == 0)
                            {
                                if ((index = searcher.UnsafeSearch(name.Char, name.ByteSize)) == -1)
                                {
                                    if (deSerializer.IgnoreValue() == 0)
                                    {
                                        return;
                                    }
                                }
                                else if (memberDeSerializers[index].Call(deSerializer, memberMap, ref value) == 0)
                                {
                                    return;
                                }
                                if (deSerializer.CheckNameEnd(name.Char, name.ByteSize) == 0)
                                {
                                    return;
                                }
                            }
                        }while (true);
                    }
                    else
                    {
                        do
                        {
                            if ((name.Data = deSerializer.GetName(ref name.ByteSize, ref isTagEnd)) == null)
                            {
                                return;
                            }
                            if (isTagEnd == 0)
                            {
                                if ((index = searcher.UnsafeSearch(name.Char, name.ByteSize)) == -1)
                                {
                                    name.ByteSize <<= 1;
                                    if (onUnknownName(deSerializer, ref value, ref name))
                                    {
                                        if (deSerializer.State != DeSerializeState.Success)
                                        {
                                            return;
                                        }
                                    }
                                    else
                                    {
                                        if (deSerializer.State == DeSerializeState.Success)
                                        {
                                            deSerializer.State = DeSerializeState.UnknownNameError;
                                        }
                                        return;
                                    }
                                }
                                else if (memberDeSerializers[index].Call(deSerializer, memberMap, ref value) == 0)
                                {
                                    return;
                                }
                                if (deSerializer.CheckNameEnd(name.Char, name.ByteSize) == 0)
                                {
                                    return;
                                }
                            }
                        }while (true);
                    }
                }
                finally { deSerializer.MemberMap = memberMap; }
            }
            else
            {
                deSerializer.State = DeSerializeState.MemberMap;
            }
        }