【问题标题】:Scala scalapb GeneratedMessageCompanion- do not conform to trait GeneratedMessageCompanion'sScala scalapb GeneratedMessageCompanion- 不符合 trait GeneratedMessageCompanion's
【发布时间】:2021-09-27 16:57:21
【问题描述】:

我正在尝试使用 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>

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;
} 

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

Scala 类: 嵌入Redis.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>

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

【问题讨论】:

  • 那是-v3.5.1 protobuf 版本吗?如果是这样,它与.proto 文件中的"proto2" 不匹配。
  • 是的 - v3.5.1 是版本。如果是这样,proto2 的版本可能是什么?
  • 不太清楚,但是扫描 protobuf github 提示 2.6.1 是最新的 version 2 协议。但只是在这里猜测(我使用 proto3 并让 SBT 完成创建 Scala 文件的所有工作!)
  • 试过-但没用..同样的错误

标签: scala protocol-buffers proto scalapb


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-14
    • 2018-08-13
    • 1970-01-01
    • 1970-01-01
    • 2013-11-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多