private void CreateStorageCommand(Opcode cmdType, bool noreply)
        {
            int offset = 0;
            uint flags = 0;
            long exp = 0;

            switch (cmdType)
            {
                case Opcode.Append:
                case Opcode.Prepend:
                case Opcode.AppendQ:
                case Opcode.PrependQ:
                    break;
                default:
                    flags = MemcachedEncoding.BinaryConverter.ToUInt32(_rawData,offset);
                    exp = (long)MemcachedEncoding.BinaryConverter.ToInt32(_rawData,offset+4);;
                    offset += 8;
                    break;
            }
            string key = MemcachedEncoding.BinaryConverter.GetString(_rawData, offset, _requestHeader.KeyLength);
            byte[] value = new byte[_requestHeader.ValueLength];
            Buffer.BlockCopy(_rawData, _requestHeader.KeyLength + offset, value, 0, _requestHeader.ValueLength);
            StorageCommand cmd = new StorageCommand(cmdType, key, flags, exp, _requestHeader.CAS, _requestHeader.ValueLength);
            cmd.DataBlock = value;
            cmd.NoReply = noreply;
            cmd.Opaque = _requestHeader.Opaque;
            _command = cmd;
        }
 public static byte[] BuildStorageResponse(StorageCommand command)
 {
     BinaryResponseStatus status = BinaryResponseStatus.no_error;
     ulong cas = 0;
     if (command.ExceptionOccured)
     {
         status = BinaryResponseStatus.item_not_stored;
     }
     else
     {
         switch (command.OperationResult.ReturnResult)
         {
             case Result.SUCCESS:
                 if (command.NoReply == true)
                     return null;
                 cas = (ulong)command.OperationResult.Value;
                 break;
             case Result.ITEM_EXISTS:
                 status = BinaryResponseStatus.key_exists;
                 break;
             case Result.ITEM_NOT_FOUND:
                 status = BinaryResponseStatus.key_not_found;
                 break;
             case Result.ITEM_MODIFIED:
                 status = BinaryResponseStatus.key_exists;
                 break;
             default:
                 status = BinaryResponseStatus.item_not_stored;
                 break;
         }
     }
     return BuildResposne(command.Opcode, status, command.Opaque, cas, null, null, null);
 }
示例#3
0
        private void CreateStorageCommand(string arguments, Opcode cmdType)
        {
            if (arguments == null)
            {
                CreateInvalidCommand();
                return;
            }

            string[] argumentsArray = arguments.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (argumentsArray.Length < 4 || argumentsArray.Length > 6)
            {
                CreateInvalidCommand("CLIENT_ERROR bad command line format");
                return;
            }
            else
            {
                try
                {
                    string key = argumentsArray[0];
                    uint flags = UInt32.Parse(argumentsArray[1]);
                    long expTime = long.Parse(argumentsArray[2]);
                    int bytes = int.Parse(argumentsArray[3]);

                    if (cmdType == Opcode.CAS)
                    {
                        ulong casUnique = ulong.Parse(argumentsArray[4]);
                        _command = new StorageCommand(cmdType, key, flags, expTime, casUnique, bytes);
                        if (argumentsArray.Length > 5 && argumentsArray[5] == "noreply")
                            _command.NoReply = true;
                    }
                    else
                    {
                        _command = new StorageCommand(cmdType, key, flags, expTime, bytes);
                        if (argumentsArray.Length > 4 && argumentsArray[4] == "noreply")
                            _command.NoReply = true;
                    }

                    this.State = ParserState.WaitingForData;
                }
                catch (Exception e)
                {
                    CreateInvalidCommand("CLIENT_ERROR bad command line format");
                    return;
                }
            }
        }