Ejemplo n.º 1
0
        /// <summary>
        /// 提供消息的反序列化操作
        /// </summary>
        /// <param name="buffer">包含消息数据包的字节数组</param>
        /// <param name="main">消息主码</param>
        /// <param name="sub">消息辅码</param>
        /// <returns></returns>
        private object Decode(byte[] buffer, out byte main, out byte sub)
        {
            main = sub = 0;
            try
            {
                if (buffer == null || buffer.Length < 2)
                {
                    return(null);
                }
                unsafe
                {
                    object obj;
                    int    len = buffer.Length;
                    fixed(byte *b = buffer)
                    {
                        main = b[0];
                        sub  = b[1];
                        int             typeCode = (main << 8 | sub);
                        ITypeSerializer serializer;

                        if (!BinarySerializer.CanDeserialize(typeCode, out serializer))
                        {
                            return(null);
                        }
                        try
                        {
                            obj = BinarySerializer.UnsafeDeserialize(b + 2, len, serializer); return(obj);
                        }
                        catch //(Exception ex)
                        {
                            //SystemRunErrorPorvider.CatchException(ex);
                            return(null);
                        }
                    }
                }
            }
            catch
            {
                return(null);
            }
        }