コード例 #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.Array)
                    {
                        byte *start = dataFixed + data.Start, end = start + data.Length;

                        return(SimpleSerialize.TypeDeSerializer <valueType> .DeSerialize(start, ref value, end) == end);
                    }
                }
                if (ReceiveDeSerializer == null)
                {
                    ReceiveDeSerializer = BinarySerialize.DeSerializer.YieldPool.Default.Pop() ?? new BinarySerialize.DeSerializer();
                    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 (ReceiveJsonParser == null)
            {
                ReceiveJsonParser = Json.Parser.YieldPool.Default.Pop() ?? new Json.Parser();
                ReceiveJsonParser.SetTcpServer();
            }
            return(ReceiveJsonParser.ParseTcpServer(ref data, ref value));
        }
コード例 #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 = BinarySerialize.DeSerializer.YieldPool.Default.Pop() ?? new BinarySerialize.DeSerializer();
                        receiveDeSerializer.SetTcpServer(AutoCSer.BinarySerialize.DeSerializer.DefaultConfig, null);
                    }
                    if (receiveDeSerializer.DeSerializeTcpServer(ref clientBuffer.Data, ref outputParameter))
                    {
                        clientBuffer.ReturnType = TcpServer.ReturnType.Success;
                        return;
                    }
                }
                else
                {
                    fixed(byte *dataFixed = clientBuffer.Data.Array)
                    {
                        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 = Json.Parser.YieldPool.Default.Pop() ?? new Json.Parser();
                    receiveJsonParser.SetTcpServer();
                }
                if (receiveJsonParser.ParseTcpServer(ref clientBuffer.Data, ref outputParameter))
                {
                    clientBuffer.ReturnType = TcpServer.ReturnType.Success;
                    return;
                }
            }
            clientBuffer.ReturnType = TcpServer.ReturnType.ClientDeSerializeError;
        }
コード例 #3
0
        internal bool ParseJson <valueType>(ref SubArray <byte> data, ref valueType value)
            where valueType : struct
        {
            Json.Parser parser = Interlocked.Exchange(ref ReceiveJsonParser, null);
            if (parser == null)
            {
                parser = Json.Parser.YieldPool.Default.Pop() ?? new Json.Parser();
                parser.SetTcpServer();
            }
            bool isValue = parser.ParseTcpServer(ref data, ref value);

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