Protocol buffer compiler for Scala.
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Add ISSUE_TEMPLATE.md May 30, 2016
.travis Try working around sbt/sbt-ghpages#46 Sep 30, 2018
compiler-plugin Add options to not generate lenses Nov 10, 2018
docs/src/main update sparksql version Nov 24, 2018
e2e sbt 1.2.7 (#519) Dec 1, 2018
examples/custom_options sbt 1.2.7 (#519) Dec 1, 2018
lenses/shared/src Add scalafmt Jun 6, 2018
project sbt 1.2.7 (#519) Dec 1, 2018
proptest/src/test/scala Update proptest to use protoc 3.6.0 Sep 30, 2018
protobuf/scalapb Add options to not generate lenses Nov 10, 2018
scalapb-runtime-grpc/src grpc: add ClientCalls module Sep 23, 2018
scalapb-runtime Add options to not generate lenses Nov 10, 2018
scalapbc Update ScalaPBC to 3.6.0 Sep 23, 2018
third_party/google/protobuf Update third_party protobuf from protobuf-3.3.1 Jul 15, 2017
.gitignore Merge scalapb/Lenses.git into scalapb/ScalaPB May 29, 2018
.scalafmt.conf Add scalafmt Jun 6, 2018
.travis.yml Fix .travis.yml for artifact deployment Oct 20, 2018
CHANGELOG.md Documentation Oct 28, 2018
LICENSE Initial commit Oct 13, 2014
README.md Version updates Oct 24, 2018
build.sbt grpc-java 1.17.1 (#522) Dec 9, 2018
e2e.sh update dependencies (#502) Sep 29, 2018
make_plugin_proto.sh Update generated code to 3.6.0 Sep 30, 2018
mima.sh Implement sealed oneofs Jul 5, 2018
proptest.sh Travis: break e2e and proptest into separate virtual machines for eac… Jun 11, 2017
sonatype.sbt Fix release process Jul 9, 2018
test_generated_code_checked_in.sh Update generated code to 3.6.0 Sep 30, 2018
version.sbt Setting version to 0.8.3-SNAPSHOT Oct 24, 2018

README.md

ScalaPB

Join the chat at https://gitter.im/trueaccord/ScalaPB

Build Status

ScalaPB is a protocol buffer compiler (protoc) plugin for Scala. It will generate Scala case classes, parsers and serializers for your protocol buffers.

ScalaPB generates case classes that can co-exist in the same project alongside the Java-generated code for ProtocolBuffer. This makes it easy to gradually migrate an existing project from the Java version of protocol buffers to Scala. This is achieved by having the ScalaPB generated code use the proto file as part of the package name (in contrast to Java which uses the file name in CamelCase as an outer class)

Each top-level message and enum is written to a separate Scala file. This results in a significant improvement in incremental compilations.

Another cool feature of ScalaPB is that it can optionally generate methods that convert a Java protocol buffer to a Scala protocol buffer and vice versa. This is useful if you are gradually migrating a large code base from Java protocol buffers to Scala. The optional Java conversion is required if you want to use fromAscii (parsing ASCII representation of a protocol buffer). The current implementation delegates to the Java version.

Highlights

  • Supports proto2 and proto3

  • Easily update nested structure in functional way using lenses

  • Scala.js integration

  • GRPC integration

  • Compatible with SparkSQL (through a helper library)

  • Conversion to and from JSON

  • Support user-defined options (since 0.5.29)

  • Support extensions (since 0.6.0)

Versions

Version Description
0.6.x Stable. Supports Protobuf 2.6.x to 3.5.x
0.5.x Supports Protobuf 2.6.x and Protobuf 3.1.x.
0.4.x Stable, unsupported. Works with Protobuf 2.6.x

Installing

To automatically generate Scala case classes for your messages add ScalaPB's sbt plugin to your project. Create a file named project/protoc.sbt containing the following line:

addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.19")

libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.8.1"

Add the following line to your build.sbt:

PB.targets in Compile := Seq(
  scalapb.gen() -> (sourceManaged in Compile).value
)

For additional configuration options, see ScalaPB SBT Settings documentation

Using ScalaPB

Documentation is available at ScalaPB website.

Testing

ScalaPB uses ScalaCheck to aggressively test the generated code. The test generates many different sets of proto files. The sets are growing in complexity: number of files, references to messages from other protos, message nesting and so on. Then, test data is generated to populate this protocol schema, then we check that the ScalaPB generated code behaves exactly like the reference implementation in Java.

Running the tests:

$ sbt test

The tests take a few minutes to run. There is a smaller test suite called e2e that uses the sbt plugin to compile the protos and runs a series of ScalaChecks on the outputs. To run it:

$ ./e2e.sh