为什么从proto生成python代码不生成类?



我正在尝试从proto文件生成python代码。

我的原型文件看起来像这样:

syntax = "proto3";
package display;
message Hello {
uint32 version = 1;
uint32 value = 2;
int32 id = 3;
}

我使用这个命令生成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'nntest.protox12x07x64isplay"3nx05Hellox12x0fnx07versionx18x01 x01(rx12rnx05valuex18x02 x01(rx12nnx02idx18x03 x01(x05x62x06proto3')
_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。

添加--grpc_python_out="."到protoc命令。这将生成一个带有所需类的附加脚本

最新更新