My proto
文件如下:
syntax = "proto3";
option csharp_namespace = "Proto";
message FileListRequest {
repeated File Files = 1;
}
message File {
string Path = 1;
}
message ImageFile {
File File = 1;
Size Size = 2;
bytes Content = 3;
}
message Size {
int32 Width = 1;
int32 Height = 2;
}
message SendNextFile {
}
我用以下命令编译它:
protoc --proto_path=. -I . --python_out=..\..\python\Modules\PreloadingIteratorWrapper\ .\filelist.proto
这将创建以下文件:
# -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: filelist.proto
"""Generated protocol buffer code."""
from google.protobuf.internal import builder as _builder
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import symbol_database as _symbol_database
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0e\x66ilelist.proto\"\'\n\x0f\x46ileListRequest\x12\x14\n\x05\x46iles\x18\x01 \x03(\x0b\x32\x05.File\"\x14\n\x04\x46ile\x12\x0c\n\x04Path\x18\x01 \x01(\t\"F\n\tImageFile\x12\x13\n\x04\x46ile\x18\x01 \x01(\x0b\x32\x05.File\x12\x13\n\x04Size\x18\x02 \x01(\x0b\x32\x05.Size\x12\x0f\n\x07\x43ontent\x18\x03 \x01(\x0c\"%\n\x04Size\x12\r\n\x05Width\x18\x01 \x01(\x05\x12\x0e\n\x06Height\x18\x02 \x01(\x05\"\x0e\n\x0cSendNextFileB\x08\xaa\x02\x05Protob\x06proto3')
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'filelist_pb2', globals())
if _descriptor._USE_C_DESCRIPTORS == False:
DESCRIPTOR._options = None
DESCRIPTOR._serialized_options = b'\252\002\005Proto'
_FILELISTREQUEST._serialized_start=18
_FILELISTREQUEST._serialized_end=57
_FILE._serialized_start=59
_FILE._serialized_end=79
_IMAGEFILE._serialized_start=81
_IMAGEFILE._serialized_end=151
_SIZE._serialized_start=153
_SIZE._serialized_end=190
_SENDNEXTFILE._serialized_start=192
_SENDNEXTFILE._serialized_end=206
# @@protoc_insertion_point(module_scope)
根据文档 https://developers.google.com/protocol-buffers/docs/pythontutorial该文件应该包含每种消息类型的类,但事实并非如此。为什么?
我有同样的问题。尝试使用 grpc-tools (我在另一个建议使用该工具的线程中找到了答案)我终于找到了解决方案。
只需将这个参数添加到 protoc 命令即可:--pyi_out
like:
protoc --proto_path=. -I . --python_out=..\..\python\Modules\PreloadingIteratorWrapper\ --pyi_out=..\..\python\Modules\PreloadingIteratorWrapper\ .\filelist.proto
它将为您生成 _bp2.py 以及相应的 _bp2.pyi (存根文件)。之后,您的 IDE 将看到类名称,智能感知将起作用等。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)