0

I am trying to generate Scala proto buff classes using Scalapb (https://scalapb.github.io/docs/scalapbc/). I am able to generate scala files but getting below error.

type arguments [com.huawei.utility.protobuff.embedtoRedis.embedtoRedis] do not conform to trait GeneratedMessageCompanion's type parameter bounds [A <: scalapb.GeneratedMessage with scalapb.Message[A]]

Sample.proto

syntax = "proto2";

package protobuff;

message embedtoRedis {
  required int32 StudentID = 1;
  repeated float StudentTitle = 2;
  required string Class = 3;
  optional string  color = 4;
  required string Type = 5;
} 

After compiling using below command, i got two scala classes. ScalaPbc\scalapbc-0.11.1\bin>scalapbc.bat -v3.5.1 --scala_out=C:\Users\satheesh\Documents\ScalaPbc\new sample.proto

Scala classes: EmbedtoRedis.scala SampleProto.scala

I am facing the issue in embedToRedis.scala in the following lines.

object embedtoRedis extends scalapb.GeneratedMessageCompanion[protobuff.sample.embedtoRedis] {
  implicit def messageCompanion: scalapb.GeneratedMessageCompanion[protobuff.sample.embedtoRedis] = this
  def parseFrom(`_input__`: _root_.com.google.protobuf.CodedInputStream): protobuff.sample.embedtoRedis = {
    var __requiredFields0: _root_.scala.Long = 0x7L
    var __studentID: _root_.scala.Int = 0
    val __studentTitle: _root_.scala.collection.immutable.VectorBuilder[_root_.scala.Float] = new _root_.scala.collection.immutable.VectorBuilder[_root_.scala.Float]
    var ___class: _root_.scala.Predef.String = ""
    var __color: _root_.scala.Option[_root_.scala.Predef.String] = _root_.scala.None
    var __type: _root_.scala.Predef.String = ""

Error: type arguments [com.huawei.utility.protobuff.embedtoRedis.embedtoRedis] do not conform to trait GeneratedMessageCompanion's type parameter bounds [A <: scalapb.GeneratedMessage with scalapb.Message[A]]

Can you please help if i am missing something?

Satheesh
  • 121
  • 2
  • 6
  • Is that `-v3.5.1` the protobuf version? If so, it doesn't match the `"proto2"` in the `.proto` file. – Tim Sep 27 '21 at 17:10
  • yes- v3.5.1 is the version. if so, What could be the version for proto2? – Satheesh Sep 27 '21 at 17:18
  • Don't really know, but scanning the protobuf github suggests that 2.6.1 is the latest version 2 protocol. But just guessing here (I use proto3 and get SBT to do all the work of creating the Scala files!) – Tim Sep 27 '21 at 17:22
  • Tried- But no use.. Same error – Satheesh Sep 27 '21 at 17:30

1 Answers1

0

The version of ScalaPB used to generate the source files does not match the version you use at compile time. Check that the versions of scalapbc tool (standalone source generator) and scalapb-runtime match.

thesamet
  • 6,382
  • 2
  • 31
  • 42