ScalaPB:compilePlugin 生成不合适 class

ScalaPB: compilePlugin generate inappropriate class

我正在尝试使用 Protocol Buffers 生成 Scala 案例 classes.

基本设置为: 1.In project/plugins.sbt:

  addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.0")

  libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.10.10"

2.In build.sbt:

name := "GeoService"

scalaVersion := "2.12.14"

Compile / PB.targets := Seq(
   scalapb.gen() -> (Compile / sourceManaged).value
)

 libraryDependencies ++= Seq(
     "com.thesamet.scalapb" %% "scalapb-runtime" % 
    scalapb.compiler.Version.scalapbVersion % "protobuf"
)

.proto 文件的内容:

 syntax = "proto3";

 package ru.spb.geo.model;

 import "google/protobuf/timestamp.proto";

  message GeoPoint {
       int32 id = 1;
       int32 latitude = 2;
       int32 longitude = 3;
       google.protobuf.Timestamp time = 4;
  }

但是在目标目录中它生成了非常奇怪的class“GeoPoint”(这个“短”的一部分class):

@SerialVersionUID(0L)
final case class GeoPoint(
  id: _root_.scala.Int = 0,
  latitude: _root_.scala.Int = 0,
  longitude: _root_.scala.Int = 0,
  time: _root_.scala.Option[com.google.protobuf.timestamp.Timestamp] =
  _root_.scala.None,
       unknownFields: _root_.scalapb.UnknownFieldSet =  
 .scalapb.UnknownFieldSet.empty
      ) extends scalapb.GeneratedMessage with scalapb.lenses.Updatable[GeoPoint] {
     @transient
      private[this] var __serializedSizeCachedValue: _root_.scala.Int = 0
      private[this] def __computeSerializedValue(): _root_.scala.Int = {
         var __size = 0
  
  {
    val __value = id
    if (__value != 0) {
      __size += _root_.com.google.protobuf.CodedOutputStream.computeInt32Size(1, 
 __value)
    }
  };
  
  {
    val __value = latitude
    if (__value != 0) {
      __size += _root_.com.google.protobuf.CodedOutputStream.computeInt32Size(2, 
  __value)
    }
  };

它按预期工作。生成的案例 class 具有原型中每个字段的成员。其余生成的代码负责序列化和反序列化。您可以在此处阅读有关生成的代码以及如何使用它的更多信息:https://scalapb.github.io/docs/generated-code