starwing / lua-protobuf

A Lua module to work with Google protobuf
MIT License
1.73k stars 387 forks source link

是否可以获取到每个字段的类型修饰。 #160

Closed Gowa2017 closed 2 years ago

Gowa2017 commented 2 years ago
message C2GSQueryLogin {
    repeated base.ClientResFileVersion res_file_version = 1;
}

如这么一个消息,我能获取到字段的名称 ID 和类型,但是我却不知道他应该是一个数组。

starwing commented 2 years ago

为啥不看文档呢……

pb.field() 返回了一个特定的消息里的一个域的详细信息:

  • name: 域名
  • number: schema中该域的对应数字(序号)
  • type: 域类型
  • default value: 域的默认值,没有的话是nil
  • "packed"|"repeated"| "optional":域的标签,注意并不支持required,会被当作optional
  • oneof_name:域所属的oneof块的名字,可选
  • oneof_index:域所属的oneof块的索引,可选