scala - 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]]
如果我遗漏了什么,你能帮忙吗?
解决方案
用于生成源文件的 ScalaPB 版本与您在编译时使用的版本不匹配。检查 scalapbc 工具(独立源代码生成器)和 scalapb-runtime 的版本是否匹配。
推荐阅读
- vuejs2 - Vuex - 如何检查模块是否已注册
- report - 有没有办法检查 PeopleSoft SQR 中出现的新页面操作?
- java - Javaparser - 如果发生条件,如何读取方法
- javascript - node.js中flutter而不是Buffer的等效函数或类型是什么
- r - 如何检查两个随机选择的响应是否匹配?
- laravel - 带有刀片组件和 alpine.js 的切换按钮
- prolog - 如何在两个列表中找到共同的元素?序言
- powerbi - USERELATIONSHIP 函数只能使用参与关系的两列引用
- java - 如何使用 Searchview 搜索 ButtonText?
- excel - 如何根据单元格值循环?