Skip to content

Instantly share code, notes, and snippets.

@volgar1x
Last active December 26, 2015 08:49
Show Gist options
  • Save volgar1x/7124859 to your computer and use it in GitHub Desktop.
Save volgar1x/7124859 to your computer and use it in GitHub Desktop.
/**
* should speed up Map implementations
*/
sealed class Opcode(value: String) {
if (value.length != 2)
throw new IllegalArgumentException("an opcode must be a 2 fixed length string")
def toString = value
val hashCode = value(0).toByte << 8 + value(1).toByte // must be unique
def equals(o: Any) = { // should be blazing fast
val value = o.toString
this.value.charAt(0) == value.charAt(0) && this.value.charAt(1) == value.charAt(1)
}
}
object Opcode {
implicit def string2opcode(s: String) = new Opcode(s)
}
val handlers: Map[Opcode, Deserializer] = Map(
"AA" -> AAMessage,
"AB" -> ABMessage
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment