Travis GitHub tag Gitter

protoless is a Protobuf 3 serialization library in Scala for JVM, based on automatic type class derivation to perfectly fit your models.

The type class derivation approach allows to generate type-safe Encoders and Decoders at compile-time for your own models, without code-generation. The derivation is done with Shapeless, No macro were harmed in the making of this library.

Schema-free doesn’t imply any loss of consistency. If you have one, you can still validate it at compile-time with yours models (not implemented yet).

protoless is heavily inspired by awesome work made on Circe by Travis Brown, so that the design of their public APIs has a lot in common. .

QuickStart

protoless is published to bintray.com/julien-lafont and cross-built for scala 2.11.8, and scala 2.12.3, so you can just add the following to your build:

resolvers += Resolver.bintrayRepo("julien-lafont", "maven")

libraryDependencies ++= Seq(
  "io.protoless" %% "protoless-core" % "0.0.7",
  "io.protoless" %% "protoless-generic" % "0.0.7"
)

Type sbt console to start a REPL and then paste the following the following code:

import io.protoless._, io.protoless.messages._, io.protoless.generic.auto._
// import io.protoless._
// import io.protoless.messages._
// import io.protoless.generic.auto._

case class Person(firstname: String, lastname: String, age: Option[Int], locations: Seq[String])
// defined class Person

val p = Person("John", "Doe", Some(28), Seq("Paris", "London", "New York"))
// p: Person = Person(John,Doe,Some(28),List(Paris, London, New York))

val bytes = Encoder[Person].encodeAsBytes(p) // or p.asProtobufBytes
// bytes: Array[Byte] = Array(10, 4, 74, 111, 104, 110, 18, 3, 68, 111, 101, 24, 28, 34, 5, 80, 97, 114, 105, 115, 34, 6, 76, 111, 110, 100, 111, 110, 34, 8, 78, 101, 119, 32, 89, 111, 114, 107)

Decoder[Person].decode(bytes) // or bytes.as[Person]
// res0: io.protoless.messages.Decoder.Result[Person] = Right(Person(John,Doe,Some(28),Vector(Paris, London, New York)))

No boilerplate, no runtime reflection.

What’s next ?

The next sections will focus on:

  • Library design
  • Protobuf message encoding / decoding
  • Protobuf field encoding / decoding