问题标签 [protoc]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
79 浏览

java - protoc-gen-java 代码使用 Inline object 提示语法错误

描述

我想用java调用golang grpc.我用旧的golang的consumer_proto.proto来生成java代码

过程

结果

我成功生成了我的 proto java 文件。但我发现使用内联对象提示语法错误,问题来自:

错误是:

当我运行代码时,错误是:

要覆盖的方法是最终的

它发生在 RepGetClassBySchoolD 类:

}

有没有办法使这项工作?或者有什么想法?谢谢

0 投票
1 回答
288 浏览

c++ - 在一个项目中包含多个 proto 文件会导致 protobuf_AssignDescriptorsOnce() 已经有一个主体

我从在同一个包下创建的服务器获得了多个 proto 文件。当我将多个这些 proto 文件添加到项目中时,每个 proto 文件都会生成自己的 .pb.cc 和 .h 文件,并且每个生成的文件都有以下两种方法。我需要将一些生成的 .cc 文件包含到我的一个项目中,这会导致以下两个函数的多个定义。

导致“函数已经有主体”问题的自动生成函数是 1. protobuf_AssignDescriptorsOnce() 2. protobuf_RegisterTypes(const ::std::string&)

更改包名称显然可以解决此问题,但 proto 文件是由服务器提供的,对该文件的任何更改都可能导致所有其他依赖客户端发生巨大变化。

任何解决此问题的帮助将不胜感激。

问候, Abilash.G

0 投票
0 回答
1120 浏览

protocol-buffers - 从 Maven 依赖项导入 .proto 文件?

这是我的 protoc jar 插件-

我想包含一些来自nexus 上可用的maven 存储库的导入语句——其中包含一堆proto 文件及其java 编译版本。这是一个包含 proto 文件的 jar。

如何在 protoc 路径中包含这些 proto 文件(打包在 jar 中),以便可以将 proto 文件导入到我当前的工作目录中?

问题是当我对我的项目进行 mavenize 时导入一直失败 - 找不到 .proto 文件。

我的 proto 命令被用作 protoc 的一部分,看起来像 - protoc-jar:正在执行:[C:\protocjar3624070738032398618\bin\protoc.exe, -IC:\protocjar3624070738032398618\include, -IC:myproject\src\main\resources , --java_out=C:\myproject\target\generated-sources, C:\myproject\somedummy.proto]

该命令无法访问我正在导入的 jar 的 com.custom.proto 包,并且我不确定要添加到上述配置中的 inputDirectories 设置中以使该包包含在 protoc 命令中。

PS 我可以使用这个设置 true 来获取 google.protobuf 包文件。但是,它不适用于包含 proto 文件(非标准)的其他 maven 依赖项

0 投票
0 回答
50 浏览

c++ - Protobuf 链接器错误

我正在尝试从目标文件创建一个可执行文件。这是我使用过的命令 -

但我收到错误 -

ffm.o: 在函数ffm::ffm_save_model(ffm::ffm_model&, std::string)': ffm.cpp:(.text+0x38b9): undefined reference to google::protobuf::Message::SerializeToOstream(std::ostream*) const' ffm.o: 在函数 google::protobuf::RepeatedField<int>::Reserve(int)': ffm.cpp:(.text._ZN6google8protobuf13RepeatedFieldIiE7ReserveEi[_ZN6google8protobuf13RepeatedFieldIiE7ReserveEi]+0x67): undefined reference to google::protobuf::internal::ArenaImpl::AllocateAligned(unsigned long)' ffm .cpp:(.text._ZN6google8protobuf13RepeatedFieldIiE7ReserveEi[_ZN6google8protobuf13RepeatedFieldIiE7ReserveEi]+0xfa): 未定义引用 google::protobuf::Arena::OnArenaAllocation(std::type_info const*, unsigned long) const' ffm-model.o: In function protobuf_model_2eproto::InitDefaultsFFMmodelImpl()': model.pb.cc:(.text+0x1d): 未定义引用 google::protobuf::internal::VerifyVersion(int, int, char const*)' model.pb.cc:(.text+0x22): undefined reference to google::protobuf::internal: :InitProtobufDefaults()' model.pb.cc:(.text+0x57): 未定义引用 google::protobuf::internal::OnShutdownDestroyMessage(void const*)' ffm-model.o: In function protobuf_model_2eproto::protobuf_AssignDescriptors()': model.pb.cc:(.text+0x107): 未定义引用 google::protobuf::internal::AssignDescriptors(std::string const&, google::protobuf::internal::MigrationSchema const*, google::protobuf::Message const* const*, unsigned int const*, google::protobuf::MessageFactory*, google::protobuf::Metadata*, google::protobuf::EnumDescriptor const**, google::protobuf::ServiceDescriptor const**)' ffm-model.o: In function protobuf_model_2eproto::protobuf_RegisterTypes(std::string const&)': model.pb.cc:(.text+0x188): 未定义对 google::protobuf::internal::RegisterAllTypes(google::protobuf::Metadata const*, int)' ffm-model.o: In function protobuf_model_2eproto::AddDescriptorsImpl()'的引用: model.pb.cc:(.text+0x1a2):未定义对 google::protobuf::DescriptorPool::InternalAddGeneratedFile(void const*, int)' model.pb.cc:(.text+0x1b1): undefined reference to google::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const*, void ( )(std::string const&))' ffm-model.o 的引用:在函数 FFMmodel::MergePartialFromCodedStream(google::protobuf::io::CodedInputStream*)': model.pb.cc:(.text+0x7a6): undefined reference to google::protobuf::io::CodedInputStream:: ReadTagFallback(unsigned int)' model.pb.cc:(.text+0x9db): 未定义对 google::protobuf::internal::WireFormat::SkipField(google::protobuf::io::CodedInputStream*, unsigned int, google::protobuf::UnknownFieldSet*)' ffm-model.o: In function FFMmodel::SerializeWithCachedSizes(google::protobuf::io::CodedOutputStream ) 的引用 const': model.pb.cc:(.text +0xa40): 未定义的引用 google::protobuf::internal::WireFormatLite::WriteInt32(int, int, google::protobuf::io::CodedOutputStream*)' model.pb.cc:(.text+0xa71): undefined reference to google::protobuf::internal::WireFormatLite::WriteInt32(int, int, google::protobuf::io::CodedOutputStream*)' model.pb.cc:(.text+0xaa2): undefined reference to google::protobuf::internal::WireFormatLite::WriteInt32(int, int, google::protobuf::io::CodedOutputStream*)' model.pb.cc:(.text+0xad1): undefined reference to google:: protobuf::internal::WireFormatLite::WriteBool(int, bool, google::protobuf::io::CodedOutputStream*)' model.pb.cc:(.text+0xc02): 对 google::protobuf::internal::WireFormat::SerializeUnknownFields(google::protobuf::UnknownFieldSet const&, google::protobuf::io::CodedOutputStream*)' ffm-model.o: In functionFFMmodel::InternalSerializeWithCachedSizesToArray(bool ) 的未定义引用, unsigned char*) const': model.pb.cc:(.text+0xe01): 未定义对 google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(google::protobuf::UnknownFieldSet const&, unsigned char*)' ffm-model.o: In function FFMmodel::ByteSizeLong() 的引用 const': model.pb.cc:(.text+0xec5): 未定义对 google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(google::protobuf::UnknownFieldSet const&)' model.pb.cc:(.text+0xed9): undefined reference to google的引用::protobuf::internal::WireFormatLite::Int32Size(google::protobuf::RepeatedField const&)' ffm-model.o: 在函数中 FFMmodel::MergeFrom(google::protobuf::Message const&)': model.pb.cc:(.text+0x101f): undefined reference to google::protobuf::internal::LogMessage::LogMessage(google::protobuf::LogLevel, char const*, int)' model.pb.cc:(.text+0x1035): 未定义对 google::protobuf::internal::LogMessage::operator<<(char const*)' model.pb.cc:(.text+0x104d): undefined reference to google::protobuf 的引用: :internal::LogFinisher::operator=(google::protobuf::internal::LogMessage&)' model.pb.cc:(.text+0x1061): undefined reference to google::protobuf::internal::LogMessage::~LogMessage()' model.pb.cc:(.text+0x108e): undefined reference to google::protobuf::internal::ReflectionOps::合并(google::protobuf::Message const&, google::protobuf::Message*)' model.pb.cc:(.text+0x10bc): 未定义对 `google::protobuf::internal::LogMessage:: 的引用~LogMessage()'

知道我做错了什么吗?

0 投票
1 回答
6324 浏览

android-gradle-plugin - protobuf gradle 插件无法编译

我正在尝试使用 gradle 插件编译 protobuf 文件,但出现以下错误:

不知道为什么会发生这种情况...... protobuf 文件按预期正确生成,但最后一步失败并出现这个奇怪的错误。

这是我的毕业文件:

我只是添加了 protobuf 自述文件(https://github.com/google/protobuf-gradle-plugin)中写的内容,并没有做任何花哨的东西......

0 投票
3 回答
9153 浏览

python - 为什么我的 Protobuf 消息(在 Python 中)忽略零值?

我一直在为一个项目实施 IPC 的 protobufs。出于某种原因,未设置/序列化设置为 0 的值。对于上下文,.proto 文件包含以下消息:

我使用 protoc 将文件编译为 Python _pb2 文件,然后尝试运行以下测试脚本:

当我运行它时,会打印以下输出:

似乎没有设置任何内容,或者零值被某种方式忽略了。但是,当我将值(x、y、深度等)更改为非零值(例如 0.1)时,我得到以下预期结果:

即使数字被打印出来,由于某种原因,枚举仍然不是。为什么 protobuf 会发生这种情况?默认情况下 double 类型为 0,因此 protobuf 序列化程序通过忽略它们来节省空间?那么,为什么在解析 State2 时它们没有被恢复呢?我错过了文档中的某些行吗?提前致谢!

——蒂姆

0 投票
0 回答
476 浏览

string - Python 的 Protobuf 和 protoc 版本匹配仍然断言失败

我收到此错误:

./google/protobuf/generated_message_util.h:86: const string& google::protobuf::internal::GetEmptyStringAlreadyInited(): 断言 `empty_string_ != __null' 失败。

我整天都在努力解决这个问题。所以我的项目中的流程是这样的:

我有一个在 Ubuntu 16.10 上使用 CMake 编译的 C++ 项目。经过一些处理后,我想将数据发送到使用 Keras 进行机器学习的 Python 脚本。

现在这两个脚本都可以完美地独立工作。我想将数据直接发送到 Python 脚本。所以我通过引用这个链接在 C++ 中嵌入了 Python

这再次适用于不导入 keras 的 Python 脚本。

现在,当我在这个 Python 脚本中导入 keras 时,我得到了上述错误,尽管它们都可以独立地正常工作。

首先,我收到了一个错误,因为 libprotobuf 和 protoc 版本不匹配,如下所示:

使用 TensorFlow 后端。[libprotobuf FATAL google/protobuf/stubs/common.cc:67] 这个程序需要 3.5.0 版本的 Protocol Buffer 运行时库,但是安装的版本是 3.0.0。请更新您的图书馆。如果您自己编译程序,请确保您的标头来自与链接时库相同版本的 Protocol Buffers。(“google/protobuf/descriptor.pb.cc”中的版本验证失败。)在抛出 'google::protobuf::FatalException' 的实例后调用终止 what():该程序需要 3.5.0 版的协议缓冲区运行时库,但安装的版本是 3.0.0。请更新您的图书馆。如果您自己编译程序,请确保您的标头来自与链接时库相同版本的 Protocol Buffers。

我已经使用 apt-get 安装了 protoc(apt-get 上可用的最新版本是 3.0.0),因为我发现其中一个答案是您不需要 protoc 3.5.0 就可以工作。pip3 install protobuf安装导致不匹配错误消息的 protobuf 3.5.0。

所以我卸载了这个 Python protobuf 版本并使用pip3 install protobuf==3.0.0. 这删除了不匹配错误消息。

但是现在我收到了上述错误消息。我还发现错误消息是由于 Keras 的 Tensorflow 依赖性而发生的

我该如何解决?

请帮忙

0 投票
2 回答
875 浏览

php - 更新 protolib 和 protoc 后,gRPC 不再工作

昨天我的 ubuntu 更新了(来自日志)Grpc for PHP

命令行:aptdaemon role='role-commit-packages' sender=':1.567' 升级:libprotoc-dev:amd64 (3.5.0-0~maarten0+artful, 3.5.0.1-0~maarten0+artful), libprotoc15:amd64 (3.5.0-0~maarten0+artful, 3.5.0.1-0~maarten0+artful), gnome-software-plugin-snap:amd64 (3.26.1-0ubuntu2, 3.26.1-0ubuntu2.17.10.1), gnome -软件:amd64(3.26.1-0ubuntu2、3.26.1-0ubuntu2.17.10.1)、google-chrome-stable:amd64(62.0.3202.94-1、63.0.3239.84-1)、protobuf-compiler:amd64(3.5 .0-0~maarten0+artful, 3.5.0.1-0~maarten0+artful), ubuntu-software:amd64 (3.26.1-0ubuntu2, 3.26.1-0ubuntu2.17.10.1), libprotobuf-lite15:amd64 (3.5 .0-0~maarten0+artful, 3.5.0.1-0~maarten0+artful), gnome-software-plugin-flatpak:amd64 (3.26.1-0ubuntu2, 3.26.1-0ubuntu2.17.10.1), libprotobuf15:amd64 (3.5.0-0~maarten0+artful, 3.5.0.1-0~maarten0+artful), libprotobuf-dev:amd64 (3.5.0-0~maarten0+artful, 3.5.0.1-0~maarten0+artful), gnome-software-common:amd64 (3.26.1-0ubuntu2, 3.26.1-0ubuntu2.17.10.1)

当重新启动时,我无法发出任何 Grpc 请求,我的 php.ini 文件中有 extension=grpc.so 并且昨天相同的代码工作,我也尝试在我的作曲家文件中更新它,也尝试重新安装 Grpc从我的原型文件重新创建类。由于某种原因,它不再起作用了。

我总是得到同样的回应

消息:“找不到类 'Grpc\ChannelCredentials'”

任何想法如何解决它(或出了什么问题)?

编辑:我将 docker 用于本地服务器 - 现在有可能 2 个不同的版本发生冲突吗?

0 投票
0 回答
336 浏览

java - protoc编译java的使用语法

我正在尝试将我的服务器与另一个云服务通信,该服务通过基于 Google 协议缓冲区开发的特定协议进行通信。我在 Netbeans 中编写了一个 Java 程序,它能够从这个云服务读取消息,但是这些消息以不可读的格式出现在我的控制台中。有人说我必须安装适当的协议来解释这些消息。所以,我为 Java 和 Win 安装了谷歌协议缓冲区: https ://github.com/google/protobuf/releases/tag/v3.5.0

现在,我正在尝试在 cmd 中使用 protoc 命令来编译我的 Java 程序(它从云服务读取输入消息),以便能够以可理解的格式读取传入的数据。

谁能帮我回答这两个问题:

  1. 使用 Protoc 编译 Java 程序的真实工作示例?谷歌说使用这个:protoc -I=$SRC_DIR --java_out=$DST_DIR $SRC_DIR/addressbook.proto https://developers.google.com/protocol-buffers/docs/javatutorial

但我无法使这种语法工作

  1. 此命令将生成什么输出以及如何/在何处使用它来解释我在 Netbeans 控制台中收到的消息(我的 Java 程序是在 Netbeans 中创建的)?

谢谢!

0 投票
1 回答
4115 浏览

java - 编译 protobuf 以使用原始类而不是众所周知的类型

假设我有 test.proto 文件:

如果我将其编译(使用 protoc v3.5.0)为 c# 代码,我将获得可为空的类型属性:

但如果我将其编译为 Java 代码,字段将是众所周知的类型:

我正在将项目从 proto2 移动到 proto3,因此我想避免使用众所周知的类型,因为更改相关代码需要大量工作。对于 c# 项目,我不需要修改任何内容,但在 Java 中,我需要按照以下示例进行操作:

有没有办法将proto文件编译为 Java,以便设置器接受原始类/包装器(字符串、整数等)作为参数?