Created
August 8, 2013 05:51
-
-
Save ScrapCodes/6181823 to your computer and use it in GitHub Desktop.
temp.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed trait PacketType { def name: String; def id: Int } | |
case object disconnect extends PacketType { val name = "disconnect"; val id = 0 } | |
case object connect extends PacketType { val name = "connect"; val id = 1 } | |
case object heartbeat extends PacketType { val name = "heartbeat"; val id = 2 } | |
case object message extends PacketType { val name = "message"; val id = 3 } | |
case object Json extends PacketType { val name = "json"; val id = 4 } | |
case object event extends PacketType { val name = "event"; val id = 5 } | |
case object ack extends PacketType { val name = "ack"; val id = 6 } | |
case object error extends PacketType { val name = "error"; val id = 7 } | |
case object noop extends PacketType { val name = "noop"; val id = 8 } | |
case object NewType extends PacketType {val name = "new"; val id = 9 } | |
packetType match { | |
// case PacketType.error.id | |
case error => (Reason(Option(resid).getOrElse("3") toInt), Advise(Option(adid).getOrElse("1") toInt)) | |
case message => (noreason, noAdvise, None, None, pdata) | |
// case PacketType.ack => (noreason, noAdvise, None, args, None, ackid) | |
case json => (noreason, noAdvise, (jsval \ "name").asOpt[String].getOrElse("UNNAMED_EVENT"), jsval \ "args") | |
case _ => (noreason, noAdvise) | |
} | |
G:\Scala\SocketIOPlay\module\app\socketio\Parser.scala:90: patterns after a variable pattern cannot match (SLS 8.1.1) | |
[warn] If you intended to match against object error in package socketio, you must use backticks, like: case `error` => | |
[warn] case error => (Reason(Option(resid).getOrElse("3") toInt), Advise(Option(adid).getOrElse("1") toInt)) | |
[warn] | |
______________________________________________ | |
the above gives error because there is a constraint on what case takes as case clases to patt match against. It is there to disambiguate against object (created ones not MODULE$). | |
So | |
packetType match { | |
// case PacketType.error.id | |
case NewType => "Works" | |
case m => s"I am object $m" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment