我試圖使用協議緩沖器來生成Scala案例類。
基本設定是。 1.在project/plugins.sbt中:
2. addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.0")
libraryDependencies = "com.thesamet.scalapb"/span> % "compilerplugin"/span> % "0.10.10"/span>
2.在build.sbt中:
name := "GeoService"
scalaVersion := "2.12.14"。
編譯/PB.target :=Seq(
scalapb.gen() -> (Compile / sourceManaged).value
)
libraryDependencies = Seq(
"com.thesamet.scalapb" %% "scalapb-runtime" %.
scalapb.compiler.Version.scalapbVersion % "protobuf"
)
.proto-file的內容:
syntax = "proto3"/span>;
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;
}
但是在目標目錄中,它生成了非常奇怪的 "GeoPoint "類(這個 "短 "類的一部分):
(0L)
final case class GeoPoint()
id: _root_.scala.Int = 0,
緯度。_root_.scala.Int = 0,
經度。_root_.scala.Int = 0,
時間。_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] /span>{
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_name.php?
__size = _root_.com.google.protobuf.CodedOutputStream.computeInt32Size(1,
__值)
}
};
{
val __value = latitude
if (__value != 0) {
__size = _root_.com.google.protobuf.CodedOutputStream.computeInt32Size(2,
__值)
}
};
uj5u.com熱心網友回復:
它按預期作業。生成的案例類對proto中的每個欄位都有成員。生成的代碼的其余部分負責處理序列化和反序列化。你可以在這里閱讀更多關于生成的代碼以及如何使用它。https://scalapb.github.io/docs/generated-code
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/332581.html
標籤:
