使用Google protobufs + iOS和Swift。使用官方插件将protobuf文件编译为Swift,我得到了很好的结果,但是type_id
从Swift代码中省略了,这对于我的代码正常工作是必不可少的。我相信它叫做“消息描述符”。
例如-protobuf文件包含:
message AuthRequest {
option (type_id) = 1001;
// Commissioning credential
string password = 1;
}
Swift中的结果代码:
struct AuthRequest {
// SwiftProtobuf.Message conformance is added in an extension below. See the
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages.
/// Commissioning credential
var password: String = String()
var unknownFields = SwiftProtobuf.UnknownStorage()
init() {}
}
...
extension AuthRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
static let protoMessageName: String = _protobuf_package + ".AuthRequest"
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
1: .same(proto: "password"),
]
mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
while let fieldNumber = try decoder.nextFieldNumber() {
switch fieldNumber {
case 1: try decoder.decodeSingularStringField(value: &self.password)
default: break
}
}
}
func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
if !self.password.isEmpty {
try visitor.visitSingularStringField(value: self.password, fieldNumber: 1)
}
try unknownFields.traverse(visitor: &visitor)
}
func _protobuf_generated_isEqualTo(other: AuthRequest) -> Bool {
if self.password != other.password {return false}
if unknownFields != other.unknownFields {return false}
return true
}
}
是否需要某种命令行开关/参数/其他操作才能访问Swift代码中的type_id
值?
谢谢!