示例#1
0
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="data">元数据</param>
        /// <param name="offset">元数据所在的偏移量</param>
        /// <param name="length">元数据长度</param>
        public override void Process(object instance, GetObjectAnalyseResult result, byte[] data, int offset, int length = 0)
        {
            if (length == 4)
            {
                result.SetValue(instance, new short[0]);
                return;
            }
            short[] array;
            unsafe
            {
                fixed(byte *pByte = &data[offset])
                {
                    int arrLength = *(int *)pByte;

                    array = new short[arrLength];
                    if (arrLength > 10)
                    {
                        fixed(short *point = array)
                        {
                            Buffer.MemoryCopy((void *)new IntPtr(pByte + 4), (void *)new IntPtr((byte *)point), (uint)(Size.Int16 * arrLength), (uint)(Size.Int16 * arrLength));
                            //Native.Win32API.memcpy(new IntPtr((byte*)point), new IntPtr(pByte + 4), (uint)(Size.Int16 * arrLength));
                        }
                    }
                    else
                    {
                        short *point = (short *)(pByte + 4);
                        for (int i = 0; i < arrLength; i++)
                        {
                            array[i] = *(point++);
                        }
                    }
                }
            }
            result.SetValue(instance, array);
        }
示例#2
0
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="data">元数据</param>
        /// <param name="offset">元数据所在的偏移量</param>
        /// <param name="length">元数据长度</param>
        public override void Process(object instance, GetObjectAnalyseResult result, byte[] data, int offset, int length = 0)
        {
            if (length == 4)
            {
                result.SetValue(instance, new IPEndPoint[0]);
                return;
            }
            IPEndPoint[] array;
            unsafe
            {
                int innerOffset = 0;
                fixed(byte *pByte = &data[offset])
                {
                    int arrLength = *(int *)pByte;

                    array        = new IPEndPoint[arrLength];
                    innerOffset += 4;
                    for (int i = 0; i < array.Length; i++)
                    {
                        array[i] = new IPEndPoint(new IPAddress(BitConverter.GetBytes(*(int *)(pByte + innerOffset))), *(int *)(pByte + innerOffset + 4));
                        //array[i] = new IPEndPoint(*(long*)(pByte + innerOffset), *(int*)(pByte + innerOffset + 8));
                        innerOffset += (int)Size.IPEndPoint;
                    }
                }
            }
            result.SetValue(instance, array);
        }
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="container">网络数据容器</param>
        public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
        {
            byte type;
            int  count;

            if (!container.TryReadByte(out type))
            {
                return(GetObjectResultTypes.NotEnoughData);
            }
            if (!container.TryReadInt32(out count))
            {
                return(GetObjectResultTypes.NotEnoughData);
            }
            count = count.ToLittleEndian();
            string[] value = new string[count];
            for (int i = 0; i < count; i++)
            {
                int length;
                if (!container.TryReadInt32(out length))
                {
                    return(GetObjectResultTypes.NotEnoughData);
                }
                length = length.ToLittleEndian();
                string content;
                if (!container.TryReadString(Encoding.UTF8, length, out content))
                {
                    return(GetObjectResultTypes.NotEnoughData);
                }
                value[i] = content;
            }
            result.SetValue(instance, value);
            return(GetObjectResultTypes.Succeed);
        }
 /// <summary>
 ///     从元数据转换为第三方客户数据
 /// </summary>
 /// <param name="instance">目标对象</param>
 /// <param name="result">分析结果</param>
 /// <param name="data">元数据</param>
 /// <param name="offset">元数据所在的偏移量</param>
 /// <param name="length">元数据长度</param>
 public override void Process(object instance, GetObjectAnalyseResult result, byte[] data, int offset, int length = 0)
 {
     //x86
     if (Size.IntPtr == 4)
     {
         if (result.Nullable)
         {
             result.SetValue <IntPtr?>(instance, new IntPtr(BitConverter.ToInt32(data, offset)));
         }
         else
         {
             result.SetValue(instance, new IntPtr(BitConverter.ToInt32(data, offset)));
         }
     }
     //x64
     else
     {
         if (result.Nullable)
         {
             result.SetValue <IntPtr?>(instance, new IntPtr(BitConverter.ToInt64(data, offset)));
         }
         else
         {
             result.SetValue(instance, new IntPtr(BitConverter.ToInt64(data, offset)));
         }
     }
 }
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="container">网络数据容器</param>
        public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
        {
            byte keyType, valueType;
            int count;
            if (!container.TryReadByte(out keyType)) return GetObjectResultTypes.NotEnoughData;
            if (!container.TryReadByte(out valueType)) return GetObjectResultTypes.NotEnoughData;
            if (!container.TryReadInt32(out count)) return GetObjectResultTypes.NotEnoughData;
            count = count.ToLittleEndian();
            Dictionary<string, Cell> value = new Dictionary<string, Cell>(count);
            for (int i = 0; i < count; i++)
            {
                int stringCount;
                if (!container.TryReadInt32(out stringCount)) return GetObjectResultTypes.NotEnoughData;
                stringCount = stringCount.ToLittleEndian();
                string keyContent;
                if (!container.TryReadString(Encoding.UTF8, stringCount, out keyContent)) return GetObjectResultTypes.NotEnoughData;

                Cell valueContent;
                GetObjectResultTypes type = ThriftObjectEngine.TryGetObject(typeof(Cell), container, out valueContent, true);
                if (type != GetObjectResultTypes.Succeed) return type;
                value.Add(keyContent, valueContent);
            }
            result.SetValue(instance, value);
            return GetObjectResultTypes.Succeed;
        }
 /// <summary>
 ///     ��Ԫ����ת��Ϊ�������ͻ�����
 /// </summary>
 /// <param name="instance">Ŀ�����</param>
 /// <param name="result">�������</param>
 /// <param name="container">������������</param>
 public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
 {
     MessageIdentity identity;
     if(!container.TryReadMessageIdentity(out identity)) return GetObjectResultTypes.NotEnoughData;
     result.SetValue(instance, identity);
     return GetObjectResultTypes.Succeed;
 }
示例#7
0
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="data">元数据</param>
        /// <param name="offset">元数据所在的偏移量</param>
        /// <param name="length">元数据长度</param>
        public override void Process(object instance, GetObjectAnalyseResult result, byte[] data, int offset, int length = 0)
        {
            if (length == 0 || data == null || data.Length == 0)
            {
                return;
            }
            unsafe
            {
                fixed(byte *old = &data[offset])
                {
                    int charCount = Encoding.UTF8.GetCharCount(old, length);

                    //allcate memory at thread stack.
                    if (charCount <= MemoryAllotter.CharSizeCanAllcateAtStack)
                    {
                        char *newObj = stackalloc char[charCount];
                        int   len    = Encoding.UTF8.GetChars(old, length, newObj, charCount);
                        result.SetValue(instance, new string(newObj, 0, len));
                    }
                    //allocate memory at heap.
                    else
                    {
                        fixed(char *newObj = new char[charCount])
                        {
                            int len = Encoding.UTF8.GetChars(old, length, newObj, charCount);

                            result.SetValue(instance, new string(newObj, 0, len));
                        }
                    }
                }
            }
        }
 /// <summary>
 ///     ��Ԫ����ת��Ϊ�������ͻ�����
 /// </summary>
 /// <param name="instance">Ŀ�����</param>
 /// <param name="result">�������</param>
 /// <param name="container">������������</param>
 public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
 {
     int value;
     if(!container.TryReadInt32(out value)) return GetObjectResultTypes.NotEnoughData;
     result.SetValue(instance, value.ToLittleEndian());
     return GetObjectResultTypes.Succeed;
 }
 /// <summary>
 ///     ��Ԫ����ת��Ϊ�������ͻ�����
 /// </summary>
 /// <param name="instance">Ŀ�����</param>
 /// <param name="result">�������</param>
 /// <param name="container">������������</param>
 public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
 {
     byte value;
     if(!container.TryReadByte(out value)) return GetObjectResultTypes.NotEnoughData;
     result.SetValue(instance, value);
     return GetObjectResultTypes.Succeed;
 }
 /// <summary>
 ///     从元数据转换为第三方客户数据
 /// </summary>
 /// <param name="instance">目标对象</param>
 /// <param name="result">分析结果</param>
 /// <param name="data">元数据</param>
 /// <param name="offset">元数据所在的偏移量</param>
 /// <param name="length">元数据长度</param>
 public override void Process(object instance, GetObjectAnalyseResult result, byte[] data, int offset, int length = 0)
 {
     unsafe
     {
         fixed(byte *pData = &data[offset])
         result.SetValue(instance, *(MessageIdentity *)pData);
     }
 }
示例#11
0
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="data">元数据</param>
        /// <param name="offset">元数据所在的偏移量</param>
        /// <param name="length">元数据长度</param>
        public override void Process(object instance, GetObjectAnalyseResult result, byte[] data, int offset, int length = 0)
        {
            if (length == 0)
            {
                return;
            }
            Color color = new Color(data, offset, length);

            result.SetValue(instance, color);
        }
 /// <summary>
 ///     ��Ԫ����ת��Ϊ�������ͻ�����
 /// </summary>
 /// <param name="instance">Ŀ�����</param>
 /// <param name="result">�������</param>
 /// <param name="container">������������</param>
 public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
 {
     int value;
     if(!container.TryReadInt32(out value)) return GetObjectResultTypes.NotEnoughData;
     value = value.ToLittleEndian();
     string content;
     if (!container.TryReadString(Encoding.UTF8, value, out content)) return GetObjectResultTypes.NotEnoughData;
     result.SetValue(instance, content);
     return GetObjectResultTypes.Succeed;
 }
示例#13
0
 /// <summary>
 ///     从元数据转换为第三方客户数据
 /// </summary>
 /// <param name="instance">目标对象</param>
 /// <param name="result">分析结果</param>
 /// <param name="data">元数据</param>
 /// <param name="offset">元数据所在的偏移量</param>
 /// <param name="length">元数据长度</param>
 public override void Process(object instance, GetObjectAnalyseResult result, byte[] data, int offset, int length = 0)
 {
     if (length == 0 || data == null || data.Length == 0)
     {
         return;
     }
     byte[] realData = new byte[length];
     Buffer.BlockCopy(data, offset, realData, 0, length);
     result.SetValue(instance, new Blob(realData));
 }
 /// <summary>
 ///     从元数据转换为第三方客户数据
 /// </summary>
 /// <param name="instance">目标对象</param>
 /// <param name="result">分析结果</param>
 /// <param name="data">元数据</param>
 /// <param name="offset">元数据所在的偏移量</param>
 /// <param name="length">元数据长度</param>
 public override void Process(object instance, GetObjectAnalyseResult result, byte[] data, int offset, int length = 0)
 {
     unsafe
     {
         fixed(byte *pData = &data[offset])
         {
             result.SetValue(instance, new IPEndPoint(new IPAddress(BitConverter.GetBytes(*(int *)pData)), *(int *)(pData + 4)));
         }
     }
 }
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="container">网络数据容器</param>
        public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
        {
            int value;

            if (!container.TryReadInt32(out value))
            {
                return(GetObjectResultTypes.NotEnoughData);
            }
            result.SetValue(instance, value.ToLittleEndian());
            return(GetObjectResultTypes.Succeed);
        }
 /// <summary>
 ///     从元数据转换为第三方客户数据
 /// </summary>
 /// <param name="instance">目标对象</param>
 /// <param name="result">分析结果</param>
 /// <param name="data">元数据</param>
 /// <param name="offset">元数据所在的偏移量</param>
 /// <param name="length">元数据长度</param>
 public override void Process(object instance, GetObjectAnalyseResult result, byte[] data, int offset, int length = 0)
 {
     if (result.Nullable)
     {
         result.SetValue <SByte?>(instance, Convert.ToSByte(data[offset]));
     }
     else
     {
         result.SetValue(instance, Convert.ToSByte(data[offset]));
     }
 }
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="container">网络数据容器</param>
        public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
        {
            MessageIdentity identity;

            if (!container.TryReadMessageIdentity(out identity))
            {
                return(GetObjectResultTypes.NotEnoughData);
            }
            result.SetValue(instance, identity);
            return(GetObjectResultTypes.Succeed);
        }
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="container">网络数据容器</param>
        public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
        {
            byte value;

            if (!container.TryReadByte(out value))
            {
                return(GetObjectResultTypes.NotEnoughData);
            }
            result.SetValue(instance, value);
            return(GetObjectResultTypes.Succeed);
        }
示例#19
0
 /// <summary>
 ///     从元数据转换为第三方客户数据
 /// </summary>
 /// <param name="instance">目标对象</param>
 /// <param name="result">分析结果</param>
 /// <param name="data">元数据</param>
 /// <param name="offset">元数据所在的偏移量</param>
 /// <param name="length">元数据长度</param>
 public override void Process(object instance, GetObjectAnalyseResult result, byte[] data, int offset, int length = 0)
 {
     if (result.Nullable)
     {
         result.SetValue <char?>(instance, BitConverter.ToChar(data, offset));
     }
     else
     {
         result.SetValue(instance, BitConverter.ToChar(data, offset));
     }
 }
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="data">元数据</param>
        /// <param name="offset">元数据所在的偏移量</param>
        /// <param name="length">元数据长度</param>
        public override void Process(object instance, GetObjectAnalyseResult result, byte[] data, int offset, int length = 0)
        {
            long ticks = BitConverter.ToInt64(data, offset);

            if (result.Nullable)
            {
                result.SetValue <DateTime?>(instance, new DateTime(ticks));
            }
            else
            {
                result.SetValue(instance, new DateTime(ticks));
            }
        }
示例#21
0
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="data">元数据</param>
        /// <param name="offset">元数据所在的偏移量</param>
        /// <param name="length">元数据长度</param>
        public override void Process(object instance, GetObjectAnalyseResult result, byte[] data, int offset, int length = 0)
        {
            if (length == 4)
            {
                result.SetValue(instance, new byte[0]);
                return;
            }
            int arrLength = BitConverter.ToInt32(data, offset);

            byte[] ret = new byte[arrLength];
            Buffer.BlockCopy(data, offset + 4, ret, 0, arrLength);
            result.SetValue(instance, ret);
        }
示例#22
0
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="container">网络数据容器</param>
        public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
        {
            byte keyType, valueType;
            int  count;

            if (!container.TryReadByte(out keyType))
            {
                return(GetObjectResultTypes.NotEnoughData);
            }
            if (!container.TryReadByte(out valueType))
            {
                return(GetObjectResultTypes.NotEnoughData);
            }
            if (!container.TryReadInt32(out count))
            {
                return(GetObjectResultTypes.NotEnoughData);
            }
            count = count.ToLittleEndian();
            Dictionary <string, string> value = new Dictionary <string, string>(count);

            for (int i = 0; i < count; i++)
            {
                int stringCount;
                if (!container.TryReadInt32(out stringCount))
                {
                    return(GetObjectResultTypes.NotEnoughData);
                }
                stringCount = stringCount.ToLittleEndian();
                string keyContent;
                if (!container.TryReadString(Encoding.UTF8, stringCount, out keyContent))
                {
                    return(GetObjectResultTypes.NotEnoughData);
                }

                if (!container.TryReadInt32(out stringCount))
                {
                    return(GetObjectResultTypes.NotEnoughData);
                }
                stringCount = stringCount.ToLittleEndian();
                string valueContent;
                if (!container.TryReadString(Encoding.UTF8, stringCount, out valueContent))
                {
                    return(GetObjectResultTypes.NotEnoughData);
                }
                value.Add(keyContent, valueContent);
            }
            result.SetValue(instance, value);
            return(GetObjectResultTypes.Succeed);
        }
 /// <summary>
 ///     从元数据转换为第三方客户数据
 /// </summary>
 /// <param name="instance">目标对象</param>
 /// <param name="result">分析结果</param>
 /// <param name="data">元数据</param>
 /// <param name="offset">元数据所在的偏移量</param>
 /// <param name="length">元数据长度</param>
 public override void Process(object instance, GetObjectAnalyseResult result, byte[] data, int offset, int length = 0)
 {
     unsafe
     {
         fixed(byte *pData = &data[offset])
         {
             if (result.Nullable)
             {
                 result.SetValue <Guid?>(instance, *((Guid *)pData));
             }
             else
             {
                 result.SetValue(instance, *((Guid *)pData));
             }
         }
     }
 }
示例#24
0
 /// <summary>
 ///     从元数据转换为第三方客户数据
 /// </summary>
 /// <param name="instance">目标对象</param>
 /// <param name="result">分析结果</param>
 /// <param name="data">元数据</param>
 /// <param name="offset">元数据所在的偏移量</param>
 /// <param name="length">元数据长度</param>
 public override void Process(object instance, GetObjectAnalyseResult result, byte[] data, int offset, int length = 0)
 {
     unsafe
     {
         fixed(byte *pByte = &data[offset])
         {
             if (result.Nullable)
             {
                 result.SetValue <decimal?>(instance, *(decimal *)pByte);
             }
             else
             {
                 result.SetValue(instance, *(decimal *)pByte);
             }
         }
     }
 }
示例#25
0
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="data">元数据</param>
        /// <param name="offset">元数据所在的偏移量</param>
        /// <param name="length">元数据长度</param>
        public override void Process(object instance, GetObjectAnalyseResult result, byte[] data, int offset, int length = 0)
        {
            TransactionIdentityTypes identityType = (TransactionIdentityTypes)data[offset];

            if (identityType == TransactionIdentityTypes.TCP)
            {
                result.SetValue(instance, TCPTransactionIdentity.Deserialize(data, offset, length));
            }
            else if (identityType == TransactionIdentityTypes.NamedPipe)
            {
                result.SetValue(instance, NamedPipeTransactionIdentity.Deserialize(data, offset, length));
            }
            else
            {
                throw new NotSupportedException(string.Format("#We were not support current type of Transaction-Identity yet! {0}", identityType));
            }
        }
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="container">网络数据容器</param>
        public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
        {
            int value;

            if (!container.TryReadInt32(out value))
            {
                return(GetObjectResultTypes.NotEnoughData);
            }
            value = value.ToLittleEndian();
            string content;

            if (!container.TryReadString(Encoding.UTF8, value, out content))
            {
                return(GetObjectResultTypes.NotEnoughData);
            }
            result.SetValue(instance, content);
            return(GetObjectResultTypes.Succeed);
        }
 /// <summary>
 ///     从元数据转换为第三方客户数据
 /// </summary>
 /// <param name="instance">目标对象</param>
 /// <param name="result">分析结果</param>
 /// <param name="container">网络数据容器</param>
 public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
 {
     byte type;
     int count;
     if (!container.TryReadByte(out type)) return GetObjectResultTypes.NotEnoughData;
     if (!container.TryReadInt32(out count)) return GetObjectResultTypes.NotEnoughData;
     count = count.ToLittleEndian();
     string[] value = new string[count];
     for (int i = 0; i < count; i++)
     {
         int length;
         if (!container.TryReadInt32(out length)) return GetObjectResultTypes.NotEnoughData;
         length = length.ToLittleEndian();
         string content;
         if (!container.TryReadString(Encoding.UTF8, length, out content)) return GetObjectResultTypes.NotEnoughData;
         value[i] = content;
     }
     result.SetValue(instance, value);
     return GetObjectResultTypes.Succeed;
 }
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="data">元数据</param>
        /// <param name="offset">元数据所在的便宜量</param>
        /// <param name="length">元数据长度</param>
        public override void Process(object instance, GetObjectAnalyseResult result, byte[] data, int offset, int length = 0)
        {
            if (length == 4)
            {
                result.SetValue(instance, new bool[0]);
                return;
            }
            unsafe
            {
                bool[] ret;
                fixed(byte *pByte = &data[offset])
                {
                    int arrLength = *(int *)pByte;

                    ret = new bool[arrLength];
                    if (arrLength > 10)
                    {
                        fixed(bool *bArrry = ret)
                        {
                            Buffer.MemoryCopy((void *)new IntPtr(pByte + 4), (void *)new IntPtr((byte *)bArrry), (uint)(Size.Bool * arrLength), (uint)(Size.Bool * arrLength));
                            //Native.Win32API.memcpy(new IntPtr((byte*)bArrry), new IntPtr(pByte + 4), (uint)(Size.Bool * arrLength));
                        }
                    }
                    else
                    {
                        bool *bArray = (bool *)(pByte + 4);
                        for (int i = 0; i < arrLength; i++)
                        {
                            ret[i] = *(bArray++);
                        }
                    }
                }

                result.SetValue(instance, ret);
            }
        }
示例#29
0
 /// <summary>
 ///     从元数据转换为第三方客户数据
 /// </summary>
 /// <param name="instance">目标对象</param>
 /// <param name="result">分析结果</param>
 /// <param name="container">网络数据容器</param>
 public abstract GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container);
示例#30
0
 /// <summary>
 ///     从元数据转换为第三方客户数据
 /// </summary>
 /// <param name="instance">目标对象</param>
 /// <param name="result">分析结果</param>
 /// <param name="data">元数据</param>
 /// <param name="offset">元数据所在的便宜量</param>
 /// <param name="length">元数据长度</param>
 public override void Process(object instance, GetObjectAnalyseResult result, byte[] data, int offset, int length = 0)
 {
     result.SetValue(instance, new BitFlag(data[offset]));
 }
 /// <summary>
 ///     从元数据转换为第三方客户数据
 /// </summary>
 /// <param name="instance">目标对象</param>
 /// <param name="result">分析结果</param>
 /// <param name="data">元数据</param>
 /// <param name="offset">元数据所在的偏移量</param>
 /// <param name="length">元数据长度</param>
 public abstract void Process(object instance, GetObjectAnalyseResult result, byte[] data, int offset, int length = 0);
示例#32
0
        /// <summary>
        ///     设置字段实例
        /// </summary>
        /// <param name="instance">对象实例</param>
        /// <param name="analyseResult">字段临时解析结构</param>
        /// <param name="container">网络数据容器</param>
        public static GetObjectResultTypes SetInstance(object instance, GetObjectAnalyseResult analyseResult, INetworkDataContainer container)
        {
            GetObjectAnalyseResult analyze = analyseResult;

            //热处理判断
            if (analyze.HasCacheFinished)
            {
                return(analyze.CacheProcess(instance, analyseResult, container));
            }

            #region 普通类型判断

            IThriftTypeProcessor intellectTypeProcessor = ThriftTypeProcessorMapping.Instance.GetProcessor(analyze.Property.PropertyType);
            if (intellectTypeProcessor != null)
            {
                //添加热缓存
                IThriftTypeProcessor processor = intellectTypeProcessor;
                analyze.CacheProcess     = processor.Process;
                analyze.HasEnoughData    = processor.HasEnoughData;
                analyze.HasCacheFinished = true;
                return(analyze.CacheProcess(instance, analyseResult, container));
            }

            #endregion

            #region 枚举类型判断

            //枚举类型
            if (analyze.Property.PropertyType.IsEnum)
            {
                Type enumType = Enum.GetUnderlyingType(analyze.Property.PropertyType);
                intellectTypeProcessor = ThriftTypeProcessorMapping.Instance.GetProcessor(enumType);
                if (intellectTypeProcessor == null)
                {
                    throw new Exception("Cannot support this enum type! #type: " + analyze.Property.PropertyType);
                }
                //添加热处理
                IThriftTypeProcessor processor = intellectTypeProcessor;
                analyze.CacheProcess     = processor.Process;
                analyze.HasEnoughData    = processor.HasEnoughData;
                analyze.HasCacheFinished = true;
                return(analyze.CacheProcess(instance, analyseResult, container));
            }

            #endregion

            #region 可空类型判断

            Type innerType;
            if ((innerType = Nullable.GetUnderlyingType(analyze.Property.PropertyType)) != null)
            {
                intellectTypeProcessor = ThriftTypeProcessorMapping.Instance.GetProcessor(innerType);
                if (intellectTypeProcessor != null)
                {
                    //添加热缓存
                    IThriftTypeProcessor processor = intellectTypeProcessor;
                    analyze.CacheProcess     = processor.Process;
                    analyze.HasEnoughData    = processor.HasEnoughData;
                    analyze.HasCacheFinished = true;
                    return(analyze.CacheProcess(instance, analyseResult, container));
                }
                throw new Exception("Cannot find compatible processor, #type: " + analyze.Property.PropertyType);
            }

            #endregion

            #region Thrift类型的判断

            //Thrift对象的判断
            if (analyze.Property.PropertyType.IsClass && analyze.Property.PropertyType.GetInterface(Consts.ThriftObjectFullName) != null)
            {
                //添加热缓存
                analyze.CacheProcess = delegate(object innerInstance, GetObjectAnalyseResult innerAnalyseResult, INetworkDataContainer innerContainer)
                {
                    GetObjectResultTypes r;
                    ThriftObject         tobj;
                    if ((r = ThriftObjectEngine.TryGetObject(innerAnalyseResult.Property.PropertyType, innerContainer, out tobj, true)) != GetObjectResultTypes.Succeed)
                    {
                        return(r);
                    }
                    innerAnalyseResult.SetValue(innerInstance, tobj);
                    return(GetObjectResultTypes.Succeed);
                };
                analyze.HasCacheFinished = true;
                return(analyze.CacheProcess(instance, analyseResult, container));;
            }

            #endregion

            #region 数组的判断

            if (analyze.Property.PropertyType.IsArray)
            {
                Type elementType = analyze.Property.PropertyType.GetElementType();
                intellectTypeProcessor = ArrayTypeProcessorMapping.Instance.GetProcessor(analyze.Property.PropertyType);
                if (intellectTypeProcessor != null)
                {
                    //添加热缓存
                    IThriftTypeProcessor processor = intellectTypeProcessor;
                    analyze.HasEnoughData    = processor.HasEnoughData;
                    analyze.CacheProcess     = processor.Process;
                    analyze.HasCacheFinished = true;
                    return(analyze.CacheProcess(instance, analyseResult, container));
                }
                if (elementType.IsSubclassOf(typeof(ThriftObject)))
                {
                    #region IntellectObject type array processor.

                    //add HOT cache.
                    analyze.CacheProcess = delegate(object innerInstance, GetObjectAnalyseResult innerAnalyseResult, INetworkDataContainer innerContainer)
                    {
                        if (!innerContainer.CheckEnoughSize(5))
                        {
                            return(GetObjectResultTypes.NotEnoughData);
                        }
                        byte tmpData;
                        int  arrLen;
                        if (!innerContainer.TryReadByte(out tmpData))
                        {
                            return(GetObjectResultTypes.NotEnoughData);
                        }
                        PropertyTypes arrElementType = (PropertyTypes)tmpData;
                        if (!innerContainer.TryReadInt32(out arrLen))
                        {
                            return(GetObjectResultTypes.NotEnoughData);
                        }
                        arrLen = arrLen.ToLittleEndian();
                        Func <int, ThriftObject[]> func  = ThriftObjectArrayHelper.GetFunc <ThriftObject>(analyze.Property.PropertyType);
                        ThriftObject[]             array = func(arrLen);
                        for (int i = 0; i < arrLen; i++)
                        {
                            GetObjectResultTypes r;
                            ThriftObject         tobj;
                            if ((r = ThriftObjectEngine.TryGetObject(innerAnalyseResult.Property.PropertyType.GetElementType(), innerContainer, out tobj, true)) != GetObjectResultTypes.Succeed)
                            {
                                return(r);
                            }
                            array[i] = tobj;
                        }
                        innerAnalyseResult.SetValue(innerInstance, array);
                        return(GetObjectResultTypes.Succeed);
                    };

                    #endregion
                }
                else
                {
                    throw new NotSupportedException(string.Format(ExceptionMessage.EX_NOT_SUPPORTED_VALUE, analyseResult.Attribute.Id, analyseResult.Property.Name, analyseResult.Property.PropertyType));
                }
                analyze.HasCacheFinished = true;
                return(analyze.CacheProcess(instance, analyseResult, container));
            }

            #endregion

            throw new Exception("Cannot support this data type: " + analyze.Property.PropertyType);
        }
示例#33
0
        /// <summary>
        ///     设置字段实例
        /// </summary>
        /// <param name="instance">对象实例</param>
        /// <param name="analyseResult">字段临时解析结构</param>
        /// <param name="container">网络数据容器</param>
        public static GetObjectResultTypes SetInstance(object instance, GetObjectAnalyseResult analyseResult, INetworkDataContainer container)
        {
            GetObjectAnalyseResult analyze = analyseResult;

            //热处理判断
            if (analyze.HasCacheFinished) return analyze.CacheProcess(instance, analyseResult, container);

            #region 普通类型判断

            IThriftTypeProcessor intellectTypeProcessor = ThriftTypeProcessorMapping.Instance.GetProcessor(analyze.Property.PropertyType);
            if (intellectTypeProcessor != null)
            {
                //添加热缓存
                IThriftTypeProcessor processor = intellectTypeProcessor;
                analyze.CacheProcess = processor.Process;
                analyze.HasEnoughData = processor.HasEnoughData;
                analyze.HasCacheFinished = true;
                return analyze.CacheProcess(instance, analyseResult, container);
            }

            #endregion

            #region 枚举类型判断

            //枚举类型
            if (analyze.Property.PropertyType.IsEnum)
            {
                Type enumType = Enum.GetUnderlyingType(analyze.Property.PropertyType);
                intellectTypeProcessor = ThriftTypeProcessorMapping.Instance.GetProcessor(enumType);
                if (intellectTypeProcessor == null) throw new Exception("Cannot support this enum type! #type: " + analyze.Property.PropertyType);
                //添加热处理
                IThriftTypeProcessor processor = intellectTypeProcessor;
                analyze.CacheProcess = processor.Process;
                analyze.HasEnoughData = processor.HasEnoughData;
                analyze.HasCacheFinished = true;
                return analyze.CacheProcess(instance, analyseResult, container);
            }

            #endregion

            #region 可空类型判断

            Type innerType;
            if ((innerType = Nullable.GetUnderlyingType(analyze.Property.PropertyType)) != null)
            {
                intellectTypeProcessor = ThriftTypeProcessorMapping.Instance.GetProcessor(innerType);
                if (intellectTypeProcessor != null)
                {
                    //添加热缓存
                    IThriftTypeProcessor processor = intellectTypeProcessor;
                    analyze.CacheProcess = processor.Process;
                    analyze.HasEnoughData = processor.HasEnoughData;
                    analyze.HasCacheFinished = true;
                    return analyze.CacheProcess(instance, analyseResult, container);
                }
                throw new Exception("Cannot find compatible processor, #type: " + analyze.Property.PropertyType);
            }

            #endregion

            #region Thrift类型的判断

            //Thrift对象的判断
            if (analyze.Property.PropertyType.IsClass && analyze.Property.PropertyType.GetInterface(Consts.ThriftObjectFullName) != null)
            {
                //添加热缓存
                analyze.CacheProcess = delegate(object innerInstance, GetObjectAnalyseResult innerAnalyseResult, INetworkDataContainer innerContainer)
                {
                    GetObjectResultTypes r;
                    ThriftObject tobj;
                    if ((r = ThriftObjectEngine.TryGetObject(innerAnalyseResult.Property.PropertyType, innerContainer, out tobj, true)) != GetObjectResultTypes.Succeed) return r;
                    innerAnalyseResult.SetValue(innerInstance, tobj);
                    return GetObjectResultTypes.Succeed;
                };
                analyze.HasCacheFinished = true;
                return analyze.CacheProcess(instance, analyseResult, container); ;
            }

            #endregion

            #region 数组的判断

            if (analyze.Property.PropertyType.IsArray)
            {
                Type elementType = analyze.Property.PropertyType.GetElementType();
                intellectTypeProcessor = ArrayTypeProcessorMapping.Instance.GetProcessor(analyze.Property.PropertyType);
                if (intellectTypeProcessor != null)
                {
                    //添加热缓存
                    IThriftTypeProcessor processor = intellectTypeProcessor;
                    analyze.HasEnoughData = processor.HasEnoughData;
                    analyze.CacheProcess = processor.Process;
                    analyze.HasCacheFinished = true;
                    return analyze.CacheProcess(instance, analyseResult, container);
                }
                if (elementType.IsSubclassOf(typeof (ThriftObject)))
                {
                    #region IntellectObject type array processor.

                    //add HOT cache.
                    analyze.CacheProcess = delegate(object innerInstance, GetObjectAnalyseResult innerAnalyseResult, INetworkDataContainer innerContainer)
                    {
                        if(!innerContainer.CheckEnoughSize(5)) return GetObjectResultTypes.NotEnoughData;
                        byte tmpData;
                        int arrLen;
                        if (!innerContainer.TryReadByte(out tmpData)) return GetObjectResultTypes.NotEnoughData;
                        PropertyTypes arrElementType = (PropertyTypes)tmpData;
                        if (!innerContainer.TryReadInt32(out arrLen)) return GetObjectResultTypes.NotEnoughData;
                        arrLen = arrLen.ToLittleEndian();
                        Func<int, ThriftObject[]> func = ThriftObjectArrayHelper.GetFunc<ThriftObject>(analyze.Property.PropertyType);
                        ThriftObject[] array = func(arrLen);
                        for (int i = 0; i < arrLen; i++)
                        {
                            GetObjectResultTypes r;
                            ThriftObject tobj;
                            if ((r = ThriftObjectEngine.TryGetObject(innerAnalyseResult.Property.PropertyType.GetElementType(), innerContainer, out tobj, true)) != GetObjectResultTypes.Succeed) return r;
                            array[i] = tobj;
                        }
                        innerAnalyseResult.SetValue(innerInstance, array);
                        return GetObjectResultTypes.Succeed;
                    };

                    #endregion
                }
                else throw new NotSupportedException(string.Format(ExceptionMessage.EX_NOT_SUPPORTED_VALUE, analyseResult.Attribute.Id, analyseResult.Property.Name, analyseResult.Property.PropertyType));
                analyze.HasCacheFinished = true;
                return analyze.CacheProcess(instance, analyseResult, container);
            }

            #endregion

            throw new Exception("Cannot support this data type: " + analyze.Property.PropertyType);
        }
示例#34
0
        /// <summary>
        ///     设置字段实例
        /// </summary>
        /// <param name="instance">对象实例</param>
        /// <param name="analyseResult">字段临时解析结构</param>
        /// <param name="data">元数据</param>
        /// <param name="offset">元数据偏移</param>
        /// <param name="length">元数据可用长度</param>
        public static void SetInstance(object instance, GetObjectAnalyseResult analyseResult, byte[] data, int offset, int length)
        {
            GetObjectAnalyseResult analyze = analyseResult;

            //热处理判断
            if (analyze.HasCacheFinished)
            {
                analyze.CacheProcess(instance, analyseResult, data, offset, length);
                return;
            }

            #region 普通类型判断

            IIntellectTypeProcessor intellectTypeProcessor = IntellectTypeProcessorMapping.Instance.GetProcessor(analyze.Attribute.Id) ??
                                                             IntellectTypeProcessorMapping.Instance.GetProcessor(analyze.Property.PropertyType);
            if (intellectTypeProcessor != null)
            {
                //添加热缓存
                IIntellectTypeProcessor processor = intellectTypeProcessor;
                if (intellectTypeProcessor.SupportUnmanagement)
                {
                    analyze.CacheProcess = processor.Process;
                }
                else
                {
                    analyze.CacheProcess = delegate(object innerInstance, GetObjectAnalyseResult innerAnalyseResult, byte[] parameter, int position, int len) { processor.Process(analyze.Attribute, parameter); }
                };
                analyze.CacheProcess(instance, analyseResult, data, offset, length);
                analyze.HasCacheFinished = true;
                return;
            }

            #endregion

            #region 枚举类型判断

            //枚举类型
            if (analyze.Property.PropertyType.GetTypeInfo().IsEnum)
            {
                Type enumType = Enum.GetUnderlyingType(analyze.Property.PropertyType);
                intellectTypeProcessor = IntellectTypeProcessorMapping.Instance.GetProcessor(enumType);
                if (intellectTypeProcessor == null)
                {
                    throw new System.Exception("Cannot support this enum type! #type: " + analyze.Property.PropertyType);
                }
                //添加热处理
                IIntellectTypeProcessor processor = intellectTypeProcessor;
                if (intellectTypeProcessor.SupportUnmanagement)
                {
                    analyze.CacheProcess = processor.Process;
                }
                else
                {
                    analyze.CacheProcess = delegate(object innerInstance, GetObjectAnalyseResult innerAnalyseResult, byte[] parameter, int position, int len) { processor.Process(analyze.Attribute, parameter); }
                };
                analyze.CacheProcess(instance, analyseResult, data, offset, length);
                analyze.HasCacheFinished = true;
                return;
            }

            #endregion

            #region 可空类型判断

            Type innerType;
            if ((innerType = Nullable.GetUnderlyingType(analyze.Property.PropertyType)) != null)
            {
                intellectTypeProcessor = IntellectTypeProcessorMapping.Instance.GetProcessor(innerType);
                if (intellectTypeProcessor != null)
                {
                    //添加热缓存
                    IIntellectTypeProcessor processor = intellectTypeProcessor;
                    if (intellectTypeProcessor.SupportUnmanagement)
                    {
                        analyze.CacheProcess = processor.Process;
                    }
                    else
                    {
                        analyze.CacheProcess = delegate(object innerInstance, GetObjectAnalyseResult innerAnalyseResult, byte[] parameter, int position, int len) { processor.Process(analyze.Attribute, parameter); }
                    };
                    analyze.CacheProcess(instance, analyseResult, data, offset, length);
                    analyze.HasCacheFinished = true;
                    return;
                }
                throw new System.Exception("Cannot find compatible processor, #type: " + analyze.Property.PropertyType);
            }

            #endregion

            #region 智能类型的判断

            //智能对象的判断
            if (analyze.Property.PropertyType.GetTypeInfo().IsClass&& analyze.Property.PropertyType.GetTypeInfo().GetInterface(Consts.IntellectObjectFullName) != null)
            {
                //添加热缓存
                analyze.CacheProcess = delegate(Object innerInstance, GetObjectAnalyseResult innerAnalyseResult, byte[] parameter, int position, int len)
                {
                    innerAnalyseResult.SetValue(innerInstance, IntellectObjectEngine.GetObject <IntellectObject>(analyze.Property.PropertyType, parameter, position, len));
                };
                analyze.CacheProcess(instance, analyseResult, data, offset, length);
                analyze.HasCacheFinished = true;
                return;
            }

            #endregion

            #region 数组的判断

            if (analyze.Property.PropertyType.IsArray)
            {
                Type elementType = analyze.Property.PropertyType.GetElementType();
                VT   vt          = FixedTypeManager.IsVT(elementType);
                //VT type.
                if (vt != null)
                {
                    #region VT type array processor.

                    IIntellectTypeProcessor arrayProcessor = ArrayTypeProcessorMapping.Instance.GetProcessor(analyseResult.Property.PropertyType);
                    //special optimize.
                    if (arrayProcessor != null)
                    {
                        analyze.CacheProcess = arrayProcessor.Process;
                        analyze.CacheProcess(instance, analyseResult, data, offset, length);
                    }
                    //normally process.
                    else
                    {
                        throw new DefineNoMeaningException(string.Format(ExceptionMessage.EX_VT_FIND_NOT_PROCESSOR, analyze.Attribute.Id, analyze.Property.Name, analyze.Property.PropertyType));
                    }

                    #endregion
                }
                else if (elementType.GetTypeInfo().IsSubclassOf(typeof(IntellectObject)))
                {
                    #region IntellectObject type array processor.

                    //add HOT cache.
                    analyze.CacheProcess = delegate(Object innerInstance, GetObjectAnalyseResult innerAnalyseResult, byte[] parameter, int position, int len)
                    {
                        int innerOffset = position;
                        int chunkSize   = position + len;
                        int arrLen      = BitConverter.ToInt32(parameter, innerOffset);
                        Func <int, IntellectObject[]> func = IntellectObjectArrayHelper.GetFunc <IntellectObject>(analyze.Property.PropertyType);
                        if (arrLen == 0)
                        {
                            innerAnalyseResult.SetValue(innerInstance, func(0));
                            return;
                        }
                        innerOffset += 4;
                        IntellectObject[] array = func(arrLen);
                        int   arrIndex          = 0;
                        short size;
                        do
                        {
                            size         = BitConverter.ToInt16(parameter, innerOffset);
                            innerOffset += 2;
                            if ((parameter.Length - innerOffset) < size)
                            {
                                throw new System.Exception("Illegal remaining binary data length!");
                            }
                            //use unmanagement method by default.
                            if (size == 0)
                            {
                                array[arrIndex] = null;
                            }
                            else
                            {
                                array[arrIndex] = IntellectObjectEngine.GetObject <IntellectObject>(elementType, parameter, innerOffset, size);
                            }
                            innerOffset += size;
                            arrIndex++;
                        } while (innerOffset < parameter.Length && innerOffset < chunkSize);
                        innerAnalyseResult.SetValue(innerInstance, array);
                    };

                    #endregion
                }
                else if (!(elementType == typeof(string)) && elementType.GetTypeInfo().IsSerializable)
                {
                    throw new NotSupportedException(string.Format(ExceptionMessage.EX_NOT_SUPPORTED_VALUE, analyseResult.Attribute.Id, analyseResult.Property.Name, analyseResult.Property.PropertyType));
                }
                else if (elementType == typeof(string))
                {
                    #region Any types if it can get the processor.
                    intellectTypeProcessor = ArrayTypeProcessorMapping.Instance.GetProcessor(analyze.Property.PropertyType);
                    if (intellectTypeProcessor == null)
                    {
                        throw new System.Exception("Cannot support this array element type processor! #type: " + elementType);
                    }
                    //Add hot cache.
                    analyze.CacheProcess = intellectTypeProcessor.Process;
                    #endregion
                }
                else
                {
                    throw new NotSupportedException(string.Format(ExceptionMessage.EX_NOT_SUPPORTED_VALUE, analyseResult.Attribute.Id, analyseResult.Property.Name, analyseResult.Property.PropertyType));
                }
                analyze.HasCacheFinished = true;
                analyze.CacheProcess(instance, analyseResult, data, offset, length);
                return;
            }

            #endregion

            throw new System.Exception("Cannot support this data type: " + analyze.Property.PropertyType);
        }

        #endregion
    }
}
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="data">元数据</param>
        /// <param name="offset">元数据所在的偏移量</param>
        /// <param name="length">元数据长度</param>
        public override void Process(object instance, GetObjectAnalyseResult result, byte[] data, int offset, int length = 0)
        {
            int innerOffset = offset;
            int chunkSize   = offset + length;
            int arrLen      = BitConverter.ToInt32(data, innerOffset);

            if (arrLen == 0)
            {
                result.SetValue(instance, new string[0]);
                return;
            }
            string[] strArr = new string[arrLen];
            innerOffset += 4;
            int   arrIndex = 0;
            short size;

            do
            {
                size         = BitConverter.ToInt16(data, innerOffset);
                innerOffset += 2;
                if ((data.Length - innerOffset) < size)
                {
                    throw new System.Exception("Illegal remaining binary data length!");
                }
                //use unmanagement method by default.
                if (size == 0)
                {
                    strArr[arrIndex] = null;
                }
                else
                {
                    string str;
                    unsafe
                    {
                        fixed(byte *old = &data[innerOffset])
                        {
                            int charCount = Encoding.UTF8.GetCharCount(old, size);

                            //allcate memory at thread stack.
                            if (charCount <= MemoryAllotter.CharSizeCanAllcateAtStack)
                            {
                                char *newObj = stackalloc char[charCount];
                                int   len    = Encoding.UTF8.GetChars(old, size, newObj, charCount);
                                str = new string(newObj, 0, len);
                            }
                            //allocate memory at heap.
                            else
                            {
                                fixed(char *newObj = new char[charCount])
                                {
                                    int len = Encoding.UTF8.GetChars(old, size, newObj, charCount);

                                    str = new string(newObj, 0, len);
                                }
                            }
                        }
                    }
                    strArr[arrIndex] = str;
                }
                innerOffset += size;
                arrIndex++;
            } while (innerOffset < data.Length && innerOffset < chunkSize);
            result.SetValue(instance, strArr);
        }
示例#36
0
 /// <summary>
 ///     ��Ԫ����ת��Ϊ�������ͻ�����
 /// </summary>
 /// <param name="instance">Ŀ�����</param>
 /// <param name="result">�������</param>
 /// <param name="container">������������</param>
 public abstract GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container);