Exemplo n.º 1
0
        /// <summary>
        /// 创建命令输入数据
        /// </summary>
        /// <param name="buildInfo">TCP 客户端创建命令参数</param>
        /// <returns>是否成功</returns>
        internal unsafe override TcpServer.ClientCommand.CommandBase Build(ref SenderBuildInfo buildInfo)
        {
            UnmanagedStream stream       = Socket.OutputSerializer.Stream;
            int             streamLength = stream.ByteSize;

            if (streamLength == 0 || (buildInfo.SendBufferSize - stream.ByteSize) >= CommandInfo.MaxDataSize)
            {
                stream.PrepLength(sizeof(int) * 3);
                stream.ByteSize += sizeof(int) * 2;
                if ((CommandInfo.CommandFlags & CommandFlags.JsonSerialize) == 0)
                {
                    Socket.Serialize(CommandInfo, ref InputParameter);
                }
                else
                {
                    Socket.JsonSerialize(ref InputParameter);
                }
                int dataLength = stream.ByteSize - streamLength - sizeof(int) * 2;
                if (dataLength <= Socket.MaxInputSize)
                {
                    ulong markData = Socket.Sender.SendMarkData;
                    byte *write    = stream.Data.Byte + streamLength;
                    buildInfo.IsVerifyMethod     |= CommandInfo.IsVerifyMethod;
                    *(int *)write                 = CommandInfo.Command | (int)(uint)CommandInfo.CommandFlags;
                    *(int *)(write + sizeof(int)) = dataLength;
                    if (markData != 0)
                    {
                        TcpServer.CommandBase.Mark(write + sizeof(int) * 2, markData, dataLength);
                    }
                    CommandInfo.CheckMaxDataSize(Math.Max(dataLength + sizeof(int) * 2, stream.LastPrepSize - streamLength));
                }
                else
                {
                    stream.ByteSize = streamLength;
                    ReturnType      = ReturnType.ClientBuildError;
                    IsBuildError    = true;
                    setTask();
                }
                return(LinkNext);
            }
            buildInfo.isFullSend = 1;
            return(this);
        }