Protobuf:如何在proto中描述Option [Timestamp]

时间:2018-03-22 11:36:00

标签: scala protocol-buffers protobuf-java

如何在Option[Timestamp]文件中描述以下案例类的*.proto

case class User(name: String, created: Option[Timestamp] = None)

*.proto包含:

   message User {
     string name = 1;
     how_to_describe_type_of_timestamp created = 2; // ???
   }

1 个答案:

答案 0 :(得分:2)

看起来你正在使用" proto3" (因为required上没有optionalname),在这种情况下:所有都是可选的;也许只是:

syntax = "proto3";
import "google/protobuf/timestamp.proto";
message User {
     string name = 1;
     .google.protobuf.Timestamp created = 2;
}

如果这是" proto2",那么大概是:

syntax = "proto2";
import "google/protobuf/timestamp.proto";
message User {
     required string name = 1;
     optional .google.protobuf.Timestamp created = 2;
}