Recursive Length Prefix (RLP) encoding implementation of mantis
add the line to your build.sbt
libraryDependences += "com.github.lbqds" %% "rlp" % "0.1"
then:
import rlp._
import rlp.RLPImplicits._
import rlp.RLPImplicitConversions._
case class Person(name: String, age: Int)
implicit val encDec = new RLPEncoder[Person] with RLPDecoder[Person] {
override def encode(p: Person): RLPEncodeable = RLPList(p.name, p.age)
override def decode(rlp: RLPEncodeable): Person = rlp match {
case RLPList(name, age) => Person(name, age)
case _ => throw new RuntimeException("invalid encode person")
}
}
val lbqds = Person("lbqds", 23)
val rlp = encode(lbqds)
val decoded = decode[Person](rlp)
assert(lbqds == decoded)
serialize:
case class Person(name: String, age: Int) extends RLPSerializable {
override def toRLPEncodable: RLPEncodeable = {
RLPList(name, age)
}
}
remove akka.util.ByteString and UInt256 from original implementation
implement akka.serialization.Serializer with rlp