Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Simon committed Mar 15, 2016
2 parents 0a9877f + a0644d7 commit b32d27a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 96 deletions.

This file was deleted.

34 changes: 7 additions & 27 deletions colossus/src/main/scala/colossus/protocols/memcache/Memcache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import DataSize._
* I've grabbed a snippet from memcached docs about ttls found here: https://github.com/memcached/memcached/blob/master/doc/protocol.txt
*
* TTLs can be a unix timestamp for an integer that is no more than 30 days in seconds (2592000 seconds). If the TTL is greater
* than 30 days in seconds, the server will consider it to be real Unix time value rather than an offset from current time.
*
* than 30 days in seconds, the server will consider it to be real Unix time value rather than an offset from current time.
*
*/

object UnifiedProtocol {
Expand Down Expand Up @@ -51,21 +51,6 @@ object MemcacheCommand {

import UnifiedProtocol._



def validateKey(key: ByteString) : Unit = {
if (key.isEmpty) throw new MemcacheEmptyKeyException
if (key.length > 250) throw new MemcacheKeyTooLongException(key)
if (key.length > 1) {
for (ix <- 0 until key.length - 1) {
if (key(ix) == 0x20 || (key(ix) == 0x0D && key(ix + 1) == 0x0A)) {
throw new MemcacheInvalidCharacterException(key, ix + 1)
}
}
}
if (key.last == 0x20) throw new MemcacheInvalidCharacterException(key, key.length)
}

case class Get(keys: ByteString*) extends MemcacheCommand {

val commandName = GET
Expand All @@ -79,7 +64,6 @@ object MemcacheCommand {
b.sizeHint(GET.size + totalKeyBytes + 2)
b.append(GET)
keys.foreach{x =>
validateKey(x)
b.append(SP).append(x)
}
b.append(RN).result()
Expand All @@ -89,15 +73,15 @@ object MemcacheCommand {
case class Set(key: ByteString, value: ByteString, ttl: Int = 0, flags : Int = 0) extends MemcacheWriteCommand {
val commandName = SET
}

case class Add(key: ByteString, value: ByteString, ttl: Int = 0, flags : Int = 0) extends MemcacheWriteCommand {
val commandName = ADD
}

case class Replace(key: ByteString, value: ByteString, ttl: Int = 0, flags : Int = 0) extends MemcacheWriteCommand {
val commandName = REPLACE
}

// Append does not take <flags> or <expiretime> but we have to provide them according to the protocol
case class Append(key: ByteString, value: ByteString) extends MemcacheWriteCommand {
val commandName = APPEND
Expand Down Expand Up @@ -137,7 +121,6 @@ object MemcacheCommand {

sealed trait CounterCommand extends MemcacheCommand{
def formatCommand(commandName : ByteString, key : ByteString, value : Long) : ByteString = {
validateKey(key)
val b = new ByteStringBuilder
val valStr = ByteString(value.toString)
b.sizeHint(commandName.size + key.size + valStr.length + 4) //4 bytes one each for 2 spaces and an \r\n
Expand Down Expand Up @@ -166,7 +149,6 @@ object MemcacheCommand {
val commandName = TOUCH

assert(ttl > 0, "TTL Must be a non negative number")
validateKey(key)

def bytes(c: Compressor = NoCompressor) = {
val b = new ByteStringBuilder
Expand Down Expand Up @@ -233,8 +215,6 @@ sealed trait MemcacheWriteCommand extends MemcacheCommand {

val sizeHint = commandName.length + flagsStr.length + ttlStr.length + dataSizeStr.length + value.size + padding

validateKey(key)

b.sizeHint(sizeHint)
b.append(commandName)
b.append(SP)
Expand Down Expand Up @@ -295,7 +275,7 @@ object MemcacheReply {
case object Deleted extends MemcacheReply with MemcacheHeader
case object NotStored extends MemcacheReply with MemcacheHeader
case object Exists extends MemcacheReply with MemcacheHeader

}

class MemcacheReplyParser(maxSize: DataSize = MemcacheReplyParser.DefaultMaxSize) {
Expand Down Expand Up @@ -336,7 +316,7 @@ object MemcacheReplyParser {
}}

def isNumeric(str : String) = str.forall(_.isDigit)

//returns either a Value or Values object depending if 1 or >1 values received
def values(build: Vector[Value]): Parser[DataReply] = delimitedString(' ', '\r') <~ byte |>{pieces => pieces.head match {
case "VALUE" => value(build, pieces(1), pieces(2).toInt, pieces(3).toInt)
Expand Down

0 comments on commit b32d27a

Please sign in to comment.