Example #1
0
        internal bool DeSerialize <valueType>(ref SubArray <byte> data, ref valueType value, bool isSimpleSerialize)
            where valueType : struct
        {
            if ((CommandIndex & (uint)CommandFlags.JsonSerialize) == 0)
            {
                if (isSimpleSerialize)
                {
                    fixed(byte *dataFixed = data.GetFixedBuffer())
                    {
                        byte *start = dataFixed + data.Start, end = start + data.Length;

                        return(SimpleSerialize.TypeDeSerializer <valueType> .DeSerialize(start, ref value, end) == end);
                    }
                }
                if (ReceiveDeSerializer == null)
                {
                    ReceiveDeSerializer = AutoCSer.BinaryDeSerializer.YieldPool.Default.Pop() ?? new AutoCSer.BinaryDeSerializer();
                    ReceiveDeSerializer.SetTcpServer(binaryDeSerializeConfig, this);
                }
                return(ReceiveDeSerializer.DeSerializeTcpServer(ref data, ref value));
                //if (ReceiveDeSerializer.DeSerializeTcpServer(ref data, ref value)) return true;
                //if (data.Length > 1 << 20) System.IO.File.WriteAllBytes((++testIdentity).ToString() + "." + data.Length.ToString(), data.ToArray());
                //return false;
            }
            if (ReceiveJsonDeSerializer == null)
            {
                ReceiveJsonDeSerializer = AutoCSer.JsonDeSerializer.YieldPool.Default.Pop() ?? new AutoCSer.JsonDeSerializer();
                ReceiveJsonDeSerializer.SetTcpServer();
            }
            return(ReceiveJsonDeSerializer.DeSerializeTcpServer(ref data, ref value));
        }
Example #2
0
        /// <summary>
        /// 数据反序列化
        /// </summary>
        /// <typeparam name="outputParameterType"></typeparam>
        /// <param name="commandInfo"></param>
        /// <param name="outputParameter"></param>
        /// <param name="clientBuffer"></param>
        private unsafe void deSerialize <outputParameterType>(TcpServer.CommandInfoBase commandInfo, ref outputParameterType outputParameter, ref ClientBuffer clientBuffer)
            where outputParameterType : struct
        {
            if ((commandInfo.CommandFlags & TcpServer.CommandFlags.JsonSerialize) == 0)
            {
                if (commandInfo.SimpleSerializeOutputParamter == 0)
                {
                    if (receiveDeSerializer == null)
                    {
                        receiveDeSerializer = AutoCSer.BinaryDeSerializer.YieldPool.Default.Pop() ?? new AutoCSer.BinaryDeSerializer();
                        receiveDeSerializer.SetTcpServer(AutoCSer.BinaryDeSerializer.DefaultConfig, null);
                    }
                    if (receiveDeSerializer.DeSerializeTcpServer(ref clientBuffer.Data, ref outputParameter))
                    {
                        clientBuffer.ReturnType = TcpServer.ReturnType.Success;
                        return;
                    }
                }
                else
                {
                    fixed(byte *dataFixed = clientBuffer.Data.GetFixedBuffer())
                    {
                        byte *start = dataFixed + clientBuffer.Data.Start, end = start + clientBuffer.Data.Length;

                        if (SimpleSerialize.TypeDeSerializer <outputParameterType> .DeSerialize(start, ref outputParameter, end) == end)
                        {
                            clientBuffer.ReturnType = TcpServer.ReturnType.Success;
                            return;
                        }
                    }
                }
            }
            else
            {
                if (receiveJsonParser == null)
                {
                    receiveJsonParser = AutoCSer.JsonDeSerializer.YieldPool.Default.Pop() ?? new AutoCSer.JsonDeSerializer();
                    receiveJsonParser.SetTcpServer();
                }
                if (receiveJsonParser.DeSerializeTcpServer(ref clientBuffer.Data, ref outputParameter))
                {
                    clientBuffer.ReturnType = TcpServer.ReturnType.Success;
                    return;
                }
            }
            clientBuffer.ReturnType = TcpServer.ReturnType.ClientDeSerializeError;
        }
Example #3
0
        internal bool DeSerializeJson <valueType>(ref SubArray <byte> data, ref valueType value)
            where valueType : struct
        {
            AutoCSer.JsonDeSerializer jsonDeSerializer = Interlocked.Exchange(ref ReceiveJsonDeSerializer, null);
            if (jsonDeSerializer == null)
            {
                jsonDeSerializer = AutoCSer.JsonDeSerializer.YieldPool.Default.Pop() ?? new AutoCSer.JsonDeSerializer();
                jsonDeSerializer.SetTcpServer();
            }
            bool isValue = jsonDeSerializer.DeSerializeTcpServer(ref data, ref value);

            if (Interlocked.CompareExchange(ref ReceiveJsonDeSerializer, jsonDeSerializer, null) != null)
            {
                jsonDeSerializer.Free();
            }
            return(isValue);
        }