我目前正在尝试从proto文件生成python代码。
我的proto文件看起来像这样:
syntax = "proto3";
package display;
message Hello {
uint32 version = 1;
uint32 value = 2;
int32 id = 3;
}
字符串
我使用这个protoc命令来生成python代码:
protoc -I="." --python_out="." test.proto
型
下面是生成的python文件:
# -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: test.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\ntest.proto\x12\x07\x64isplay\"3\n\x05Hello\x12\x0f\n\x07version\x18\x01 \x01(\r\x12\r\n\x05value\x18\x02 \x01(\r\x12\n\n\x02id\x18\x03 \x01(\x05\x62\x06proto3')
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'test_pb2', globals())
if _descriptor._USE_C_DESCRIPTORS == False:
DESCRIPTOR._options = None
_HELLO._serialized_start=23
_HELLO._serialized_end=74
# @@protoc_insertion_point(module_scope)
型
它看起来一点也不像这个页面上的Google文档:https://developers.google.com/protocol-buffers/docs/pythontutorial
你知道为什么没有生成元类吗?
我使用Python 3.9和最新版本的protobuf包和最新版本的protoc。
1条答案
按热度按时间x8goxv8g1#
添加
--grpc_python_out="."
到这protoc命令.这将产生一个额外的脚本与这需要的classes