Search code examples
scalaprotocol-buffersscalapb

Compiling protocol buffers with ScalaPBC for Scala 2.10?


I'm trying to compile a simple protobuf file to Scala using Trueaccord's ScalaPBC. I'm restricted to Scala 2.10, and the resulting classes cannot be compiled due to an implementation restriction on case classes ("case classes cannot have more than 22 parameters").

I use Trueaccord's scalapb-runtime and compilerplugin for Scala 2.10 version 0.4.20 and protobuf-java version 2.6.1.

This is the protobuf I'm compiling (the fields have no meaning really):

message Person {
  required string name = 1;
  required int32 id = 2;
  optional string email = 3;
  optional string email1 = 4;
  optional string email2 = 5;
  optional string email3 = 6;
  optional string email4 = 7;
  optional string email5 = 8;
  optional string email6 = 9;
  optional string email7 = 10;
  optional string email8 = 11;
  optional string email9 = 12;
  optional string email0 = 13;
  optional string emaila = 14;
  optional string emails = 15;
  optional string emaild = 16;
  optional string emailf = 17;
  optional string emailg = 18;
  optional string emailh = 19;
  optional string emailj = 20;
  optional string emailk = 21;
  optional string emaill = 22;
  optional string emailz = 23;
  optional string emailx = 24;
  optional string emailc = 25;
  optional string emailv = 26;
  optional string emailb = 27;
  optional string emailn = 28;
  optional string emailm = 29;
  optional string emailkk = 30;
}

Is there a way to compile the above protobuf into Scala code that works with Scala 2.10?


Solution

  • Unfortunately not. In Scala 2.10, ScalaPB is limited to messages with 22 fields or less.

    If you are able to change the structure of your protocol buffer, consider using nested messages or repeated fields to reduce the number of fields you have in each message.