Skip to content

Instantly share code, notes, and snippets.

@codedmart
Created March 24, 2015 19:15
Show Gist options
  • Save codedmart/af48389f40e948857bf8 to your computer and use it in GitHub Desktop.
Save codedmart/af48389f40e948857bf8 to your computer and use it in GitHub Desktop.
package com.scalaRethinkdb
object VersionDummy {
trait Version extends Wire[Version] {
def fromWire(a: Int): Version = a match {
case 0x5f75e83e => V0_3
case 0x400c2d20 => V0_4
case _ => throw new RethinkDbUnexpectedResponseError("Version not found.")
}
}
// Really just here as an alias for fromWire
case object Versions extends Version {
val toWire = 0
}
case object V0_3 extends Version {
val toWire = 0x5f75e83e
}
case object V0_4 extends Version {
val toWire = 0x400c2d20
}
trait Protocol extends Wire[Protocol] {
def fromWire(a: Int): Protocol = a match {
case 0x7e6970c7 => JSON
case _ => throw new RethinkDbUnexpectedResponseError("Protocol not found.")
}
}
// Really just here as an alias for fromWire
case object Protocols extends Protocol {
val toWire = 0
}
case object JSON extends Protocol {
val toWire = 0x7e6970c7
}
}
package com.scalaRethinkdb
import org.scalatest.{WordSpec, Matchers}
class VersionDummySpec extends WordSpec with Matchers {
"Version" should {
"toWire properly" in {
VersionDummy.V0_3.toWire should be (1601562686)
VersionDummy.V0_4.toWire should be (1074539808)
}
"fromWire properly" in {
VersionDummy.Versions.fromWire(0x5f75e83e) should be (VersionDummy.V0_3)
VersionDummy.Versions.fromWire(0x400c2d20) should be (VersionDummy.V0_4)
}
}
"JSON" should {
"toWire properly" in {
VersionDummy.JSON.toWire should be (2120839367)
}
"fromWire properly" in {
VersionDummy.Protocols.fromWire(0x7e6970c7) should be (VersionDummy.JSON)
}
}
}
package com.scalaRethinkdb
trait Wire[T] {
val toWire: Int
def fromWire(wire: Int): T
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment