private object Deserialize(BinaryResponse response, String key = null)
        {
            key = key ?? response.KeyAsString;
            SerializedType type = SerializedType.ByteArray;

            if (response.Extras.Length >= 4)
            {
                type = (SerializedType)BinaryMessage.NetworkUInt16(response.Extras, 2);
            }
            return(Deserialize(key, type, response.Value));
        }
        private BinaryResponse store(string command, string key, bool keyIsChecked, object value, uint hash, int expiry,
                                     ulong unique)
        {
            if (!keyIsChecked)
            {
                checkKey(key);
            }

            return(serverPool.Execute <BinaryResponse>(hash, null, delegate(PooledSocket socket) {
                SerializedType type;
                byte[] bytes;

                //Serialize object efficiently, store the datatype marker in the flags property.
                try {
                    bytes = Serializer.Serialize(value, out type, CompressionThreshold);
                }
                catch (Exception e) {
                    //If serialization fails, return false;

                    logger.Error("Error serializing object for key '" + key + "'.", e);
                    return null;
                }
                byte[] extras = new byte[8];
                Array.Copy(BinaryMessage.NetworkOrder(BitConverter.GetBytes((int)type)), 0, extras, 0, 4);
                Array.Copy(BinaryMessage.NetworkOrder(BitConverter.GetBytes(expiry)), 0, extras, 4, 4);
                var request = new BinaryRequest()
                {
                    Extras = extras,
                    Value = bytes,
                    KeyAsString = keyPrefix + key
                };
                //Create commandline
                switch (command)
                {
                case "set":
                    request.Opcode = Opcodes.Set;
                    break;

                case "add":
                    request.Opcode = Opcodes.Add;
                    break;

                case "replace":
                    request.Opcode = Opcodes.Replace;
                    break;

                case "append":
                    extras = new byte[] {};
                    request.Opcode = Opcodes.Append;
                    break;

                case "prepend":
                    extras = new byte[] {};
                    request.Opcode = Opcodes.Prepend;
                    break;

                case "cas":
                    request.Opcode = Opcodes.Set;
                    request.CAS = unique;
                    break;
                }

                //Write commandline and serialized object.
                socket.Write(request);
                return socket.ReadBinaryResponse();
            }));
        }