Skip to content
SandroGrzicic edited this page Aug 21, 2011 · 7 revisions

Processing .proto files

In addition to running the command-line interface, ScalaBuff can also be used programatically, from your own code.

For this purpose, the ScalaBuff object offers several methods. Each of these methods returns a ScalaClass case class that contains the String body of the generated class, along with the full path (package name) to the file and file name, if applicable.

  • apply(resourcePath: String): the default method, runs the ScalaBuff generator on the specified resource path (file path or URL).

  • fromString(input: String): instead of parsing the parameter as a file path or URL, ScalaBuff.fromString takes the input .proto file itself as a parameter.

The processing is split into two phases: Parsing the input and generating the output using the parsed input. On a parsing error, a ParsingFailureException is thrown. If parsing succeeds but generation fails, a GenerationFailureException will be thrown. Both of these RuntimeExceptions contain a helpful message regarding what went wrong with processing the input.

Parser

Generator

Clone this wiki locally