使用 ScalaPBC 为 Scala 2.10 编译协议缓冲区?
Compiling protocol buffers with ScalaPBC for Scala 2.10?
我正在尝试使用 Trueaccord 的 ScalaPBC 将一个简单的 protobuf 文件编译为 Scala。
我仅限于 Scala 2.10,由于对 case 类 ("case classes cannot have more than 22 parameters").
的实现限制,无法编译生成的 类
我将 Trueaccord 的 scalapb-runtime 和 compilerplugin 用于 Scala 2.10 版本 0.4.20 和 protobuf-java 版本 2.6.1。
这是我正在编译的 protobuf(这些字段实际上没有任何意义):
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;
}
有没有办法将上面的 protobuf 编译成适用于 Scala 2.10 的 Scala 代码?
不幸的是没有。在 Scala 2.10 中,ScalaPB 仅限于具有 22 个或更少字段的消息。
如果您能够更改协议缓冲区的结构,请考虑使用嵌套消息或重复字段来减少每条消息中的字段数量。
我正在尝试使用 Trueaccord 的 ScalaPBC 将一个简单的 protobuf 文件编译为 Scala。 我仅限于 Scala 2.10,由于对 case 类 ("case classes cannot have more than 22 parameters").
的实现限制,无法编译生成的 类我将 Trueaccord 的 scalapb-runtime 和 compilerplugin 用于 Scala 2.10 版本 0.4.20 和 protobuf-java 版本 2.6.1。
这是我正在编译的 protobuf(这些字段实际上没有任何意义):
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;
}
有没有办法将上面的 protobuf 编译成适用于 Scala 2.10 的 Scala 代码?
不幸的是没有。在 Scala 2.10 中,ScalaPB 仅限于具有 22 个或更少字段的消息。
如果您能够更改协议缓冲区的结构,请考虑使用嵌套消息或重复字段来减少每条消息中的字段数量。