Exemple #1
0
 /// <summary>
 /// 枚举值解析
 /// </summary>
 /// <param name="jsonDeSerializer">JSON 反序列化</param>
 /// <param name="value">目标数据</param>
 public static void DeSerializeFlags(JsonDeSerializer jsonDeSerializer, ref T value)
 {
     if (!tryDeSerializeNumber(jsonDeSerializer, ref value))
     {
         if (enumSearcher.State == null)
         {
             if (jsonDeSerializer.Config.IsMatchEnum)
             {
                 jsonDeSerializer.DeSerializeState = DeSerializeState.NoFoundEnumValue;
             }
             else
             {
                 jsonDeSerializer.Ignore();
             }
         }
         else
         {
             int index, nextIndex = -1;
             getIndex(jsonDeSerializer, ref value, out index, ref nextIndex);
             if (nextIndex != -1)
             {
                 ulong intValue = enumInts.ULong[index];
                 intValue |= enumInts.ULong[nextIndex];
                 while (jsonDeSerializer.Quote != 0)
                 {
                     index = enumSearcher.NextFlagEnum(jsonDeSerializer);
                     if (jsonDeSerializer.DeSerializeState == DeSerializeState.Success)
                     {
                         if (index != -1)
                         {
                             intValue |= enumInts.ULong[index];
                         }
                     }
                     else
                     {
                         return;
                     }
                 }
                 value = AutoCSer.Metadata.EnumGenericType <T, ulong> .FromInt(intValue);
             }
         }
     }
 }
        /// <summary>
        /// 数据成员解析
        /// </summary>
        /// <param name="jsonDeSerializer">Json解析器</param>
        /// <param name="value">目标数据</param>
        internal static void DeSerializeMembers(JsonDeSerializer jsonDeSerializer, ref T value)
        {
#if NOJIT
            byte *names = memberNames.Byte;
#endif
            DeSerializeConfig config    = jsonDeSerializer.Config;
            MemberMap         memberMap = jsonDeSerializer.MemberMap;
            if (memberMap == null)
            {
#if NOJIT
                int index = 0;
                while ((names = jsonDeSerializer.IsName(names, ref index)) != null)
                {
                    if (index == -1)
                    {
                        return;
                    }
                    memberDeSerializers[index].TryDeSerialize(jsonDeSerializer, ref value);
                    if (jsonDeSerializer.DeSerializeState != DeSerializeState.Success)
                    {
                        return;
                    }
                    ++index;
                }
#else
                int index = deSerializeMember(jsonDeSerializer, ref value, memberNames.Byte);
                if (index == -1)
                {
                    return;
                }
#endif
                if (index == 0 ? jsonDeSerializer.IsFirstObject() : jsonDeSerializer.IsNextObject())
                {
                    bool isQuote;
                    if (onUnknownName == null)
                    {
                        do
                        {
                            if ((index = memberSearcher.SearchName(jsonDeSerializer, out isQuote)) != -1)
                            {
                                if (jsonDeSerializer.SearchColon() == 0)
                                {
                                    return;
                                }
                                memberDeSerializers[index].TryDeSerialize(jsonDeSerializer, ref value);
                            }
                            else
                            {
                                if (jsonDeSerializer.DeSerializeState != DeSerializeState.Success)
                                {
                                    return;
                                }
                                if (isQuote)
                                {
                                    jsonDeSerializer.SearchStringEnd();
                                }
                                else
                                {
                                    jsonDeSerializer.SearchNameEnd();
                                }
                                if (jsonDeSerializer.DeSerializeState != DeSerializeState.Success || jsonDeSerializer.SearchColon() == 0)
                                {
                                    return;
                                }
                                jsonDeSerializer.Ignore();
                            }
                        }while (jsonDeSerializer.DeSerializeState == DeSerializeState.Success && jsonDeSerializer.IsNextObject());
                    }
                    else
                    {
                        AutoCSer.Memory.Pointer name;
#if !Serialize
                        name.CurrentIndex = 0;
#endif
                        do
                        {
                            name.Data = jsonDeSerializer.Current;
                            if ((index = memberSearcher.SearchName(jsonDeSerializer, out isQuote)) != -1)
                            {
                                if (jsonDeSerializer.SearchColon() == 0)
                                {
                                    return;
                                }
                                memberDeSerializers[index].TryDeSerialize(jsonDeSerializer, ref value);
                            }
                            else
                            {
                                if (jsonDeSerializer.DeSerializeState != DeSerializeState.Success)
                                {
                                    return;
                                }
                                if (isQuote)
                                {
                                    jsonDeSerializer.SearchStringEnd();
                                }
                                else
                                {
                                    jsonDeSerializer.SearchNameEnd();
                                }
                                if (jsonDeSerializer.DeSerializeState != DeSerializeState.Success)
                                {
                                    return;
                                }
                                name.ByteSize = (int)((byte *)jsonDeSerializer.Current - (byte *)name.Data);
                                if (jsonDeSerializer.SearchColon() == 0)
                                {
                                    return;
                                }
                                if (isQuote)
                                {
                                    name.Data      = name.Byte + 2;
                                    name.ByteSize -= 4;
                                }
                                onUnknownName(jsonDeSerializer, ref value, ref name);
                                if (jsonDeSerializer.DeSerializeState != DeSerializeState.Success)
                                {
                                    return;
                                }
                            }
                        }while (jsonDeSerializer.IsNextObject());
                    }
                }
            }
            else if (object.ReferenceEquals(memberMap.Type, MemberMap <T> .MemberMapType))
            {
                try
                {
                    memberMap.Empty();
                    jsonDeSerializer.MemberMap = null;
#if NOJIT
                    int index = 0;
                    while ((names = jsonDeSerializer.IsName(names, ref index)) != null)
                    {
                        if (index == -1)
                        {
                            return;
                        }
                        memberDeSerializers[index].Call(jsonDeSerializer, memberMap, ref value);
                        if (jsonDeSerializer.DeSerializeState != DeSerializeState.Success)
                        {
                            return;
                        }
                        ++index;
                    }
#else
                    int index = deSerializeMemberMap(jsonDeSerializer, ref value, memberNames.Byte, memberMap);
                    if (index == -1)
                    {
                        return;
                    }
#endif
                    if (index == 0 ? jsonDeSerializer.IsFirstObject() : jsonDeSerializer.IsNextObject())
                    {
                        bool isQuote;
                        if (onUnknownName == null)
                        {
                            do
                            {
                                if ((index = memberSearcher.SearchName(jsonDeSerializer, out isQuote)) != -1)
                                {
                                    if (jsonDeSerializer.SearchColon() == 0)
                                    {
                                        return;
                                    }
                                    memberDeSerializers[index].Call(jsonDeSerializer, memberMap, ref value);
                                }
                                else
                                {
                                    if (jsonDeSerializer.DeSerializeState != DeSerializeState.Success)
                                    {
                                        return;
                                    }
                                    if (isQuote)
                                    {
                                        jsonDeSerializer.SearchStringEnd();
                                    }
                                    else
                                    {
                                        jsonDeSerializer.SearchNameEnd();
                                    }
                                    if (jsonDeSerializer.DeSerializeState != DeSerializeState.Success || jsonDeSerializer.SearchColon() == 0)
                                    {
                                        return;
                                    }
                                    jsonDeSerializer.Ignore();
                                }
                            }while (jsonDeSerializer.DeSerializeState == DeSerializeState.Success && jsonDeSerializer.IsNextObject());
                        }
                        else
                        {
                            AutoCSer.Memory.Pointer name;
#if !Serialize
                            name.CurrentIndex = 0;
#endif
                            do
                            {
                                name.Data = jsonDeSerializer.Current;
                                if ((index = memberSearcher.SearchName(jsonDeSerializer, out isQuote)) != -1)
                                {
                                    if (jsonDeSerializer.SearchColon() == 0)
                                    {
                                        return;
                                    }
                                    memberDeSerializers[index].Call(jsonDeSerializer, memberMap, ref value);
                                }
                                else
                                {
                                    if (jsonDeSerializer.DeSerializeState != DeSerializeState.Success)
                                    {
                                        return;
                                    }
                                    if (isQuote)
                                    {
                                        jsonDeSerializer.SearchStringEnd();
                                    }
                                    else
                                    {
                                        jsonDeSerializer.SearchNameEnd();
                                    }
                                    if (jsonDeSerializer.DeSerializeState != DeSerializeState.Success)
                                    {
                                        return;
                                    }
                                    name.ByteSize = (int)((byte *)jsonDeSerializer.Current - (byte *)name.Data);
                                    if (jsonDeSerializer.SearchColon() == 0)
                                    {
                                        return;
                                    }
                                    if (isQuote)
                                    {
                                        name.Data      = name.Byte + 2;
                                        name.ByteSize -= 4;
                                    }
                                    onUnknownName(jsonDeSerializer, ref value, ref name);
                                    if (jsonDeSerializer.DeSerializeState != DeSerializeState.Success)
                                    {
                                        return;
                                    }
                                }
                            }while (jsonDeSerializer.IsNextObject());
                        }
                    }
                }
                finally { jsonDeSerializer.MemberMap = memberMap; }
            }
            else
            {
                jsonDeSerializer.DeSerializeState = DeSerializeState.MemberMap;
            }
        }
Exemple #3
0
 /// <summary>
 /// 自定义反序列化不支持类型
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="jsonDeSerializer">JSON 反序列化</param>
 /// <param name="value"></param>
 /// <returns></returns>
 public virtual DeSerializeState NotSupport <T>(JsonDeSerializer jsonDeSerializer, ref T value)
 {
     jsonDeSerializer.Ignore();
     return(jsonDeSerializer.DeSerializeState);
     //return DeSerializeState.NotSupport;
 }