【问题标题】:can .proto file fields be without values?.proto 文件字段可以没有值吗?
【发布时间】:2020-12-16 02:37:47
【问题描述】:

我收到“缺少字段编号”错误。是否可以声明没有值的字段?因为我没有字段的默认值。

syntax = "proto3";

package tutorial;

message Person {
  required string name;
  required string email;
}

【问题讨论】:

  • 这不是缺少的值;它是一个字段编号。但是,proto3 中不存在“必需”(“可选”存在,但指的是是否跟踪明确的分配);例如string name = 1; string email = 2;

标签: protocol-buffers proto


【解决方案1】:

字段编号不是指默认值,而是消息定义中的每个字段都有唯一的编号。这些数字用于在消息二进制格式中标识您的字段,一旦使用您的消息类型就不应更改。

More info here in the doc

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-24
    • 1970-01-01
    • 2017-04-23
    • 2019-05-18
    • 1970-01-01
    • 2020-06-27
    相关资源
    最近更新 更多