首页 > 解决方案 > Scala scalapb GeneratedMessageCompanion- 不符合 trait GeneratedMessageCompanion's

问题描述

我正在尝试使用 Scalapb ( https://scalapb.github.io/docs/scalapbc/ ) 生成 Scala proto buff 类。我能够生成 scala 文件,但出现以下错误。

类型参数 [com.huawei.utility.protobuff.embedtoRedis.embedtoRedis] 不符合 trait GeneratedMessageCompanion 的类型参数界限 [A <: scalapb.GeneratedMessage with scalapb.Message[A]]

样例.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;
} 

使用以下命令编译后,我得到了两个 scala 类。 ScalaPbc\scalapbc-0.11.1\bin>scalapbc.bat -v3.5.1 --scala_out=C:\Users\satheesh\Documents\ScalaPbc\new sample.proto

Scala 类:EmbedtoRedis.scala SampleProto.scala

我在以下几行中面临 embedToRedis.scala 中的问题。

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 = ""

错误: 类型参数 [com.huawei.utility.protobuff.embedtoRedis.embedtoRedis] 不符合 trait GeneratedMessageCompanion 的类型参数边界 [A <: scalapb.GeneratedMessage with scalapb.Message[A]]

如果我遗漏了什么,你能帮忙吗?

标签: scalaprotocol-buffersprotoscalapb

解决方案


用于生成源文件的 ScalaPB 版本与您在编译时使用的版本不匹配。检查 scalapbc 工具(独立源代码生成器)和 scalapb-runtime 的版本是否匹配。


推荐阅读