我目前收到一个错误,指出我在protoc生成的头文件中的这些行:
#if 2006001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
#endif
Run Code Online (Sandbox Code Playgroud)
但我的protoc版本与上面的版本匹配:
protoc --version
libprotoc 2.6.1
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
最初我的protoc版本是3.0.0然后通过同步回到2.6.1并执行步骤重新安装它; make distclean,./ configure,make,make install来安装所需的2.6.1版本.我需要旧版本,因为那是我们服务器中安装的版本.
我一直在尝试在我的Python程序中使用协议缓冲区,但无法使其工作.我正在运行Windows 8机器,并尝试过Python 2.7.6和Python 3.3.我下载了Python的二进制协议缓冲编译器并用它myProto_pb2.py从我的myProto.proto文件生成,但是当我运行我的Python程序时出现以下错误:
从"import myProto_pb2"行,从协议缓冲区版本2.5使用Python 2.7.6时出现以下错误:
from google.protobuf import descriptor as _descriptor
ImportError: No module named google.protobuf
Run Code Online (Sandbox Code Playgroud)
如何在Windows上从Python正确安装和运行协议缓冲区?
我正在使用grpc golang在客户端和服务器应用程序之间进行通信.下面是protoc缓冲区的代码.
syntax = "proto3";
package Trail;
service TrailFunc {
rpc HelloWorld (Request) returns (Reply) {}
}
// The request message containing the user's name.
message Request {
map<string,string> inputVar = 1;
}
// The response message containing the greetings
message Reply {
string outputVar = 1;
}
Run Code Online (Sandbox Code Playgroud)
我需要在消息数据结构中创建一个类型为map [string] interface {}的字段inputVar,而不是map [string] string.我怎样才能实现它?提前致谢.
我想了解 golang、gRPC 和 protobuf 的良好实践。
我正在实施以下 gRPC 服务
service MyService {
rpc dosomethink(model.MyModel) returns (model.Model) {
option (google.api.http) = { post: "/my/path" body: "" };
}
}
Run Code Online (Sandbox Code Playgroud)
我编译了protobufs。事实上,protobuf 给了我们一个从 http 到 grpc 的 httpproxy。
实现此服务的代码:
import "google.golang.org/grpc/status"
func (Abcd) Dosomethink(c context.Context, sessionRequest *model.MyModel) (*model.Model, error) {
return nil, status.New(400,"Default error message for 400")
}
Run Code Online (Sandbox Code Playgroud)
我想要一个 400 http 错误(在 http 代理中),消息为“400 的默认错误消息”,该消息有效,但 http 错误始终为 500。
你知道任何关于这个的帖子或文档吗?
可以澄清协议缓冲区和协议之间的区别吗?。谷歌搜索只显示协议缓冲区。我看到 protobuf-programming language-version 和 protoc-operating system-86_32 的命名约定是不同的。它们是不同的还是相同的?
使用 tensorflow 时是否需要同时安装两者?虽然
protoc --version
Run Code Online (Sandbox Code Playgroud)
是 3.6 但我的 pip 在抱怨
tensorflow-gpu 1.7.0 has requirement protobuf>=3.4.0, but you'll have protobuf 2.6.1 which is incompatible.
Run Code Online (Sandbox Code Playgroud) 当我运行这个:
protoc --python_out=. .\object_detection\protos\anchor_generator.proto
Run Code Online (Sandbox Code Playgroud)
在命令行上的 tensorflow 对象检测文件上,我得到:
'protoc' is not recognized as an internal or external command, operable program or batch file.
Run Code Online (Sandbox Code Playgroud)
我按照protoc object_detection/protos/*.proto: No such file or directory 中的所有说明进行操作,但它们从来没有为我工作过
除了我进行的搜索之外,我还尝试了以下命令:
py-3.6 -m pip install protobuf
Run Code Online (Sandbox Code Playgroud)
它对我有用。
我再次输入命令
python_out=. .\object_detection\protos\anchor_generator.proto
Run Code Online (Sandbox Code Playgroud)
但它仍然失败,这是:
C:\Users\laptop market\Downloads\bin\protoc object_detection/protos/*.proto --py_out=.
Run Code Online (Sandbox Code Playgroud)
也失败了。
我一直在尝试使用 protoc cli 实用程序对字符串进行编码。注意到输出仍然包含纯文本。我究竟做错了什么?
osboxes@osboxes:~/proto/bin$ cat ./teststring.proto
syntax = "proto2";
message Test2 {
optional string b = 2;
}
echo b:\"my_testing_string\"|./protoc --encode Test2 teststring.proto>result.out
Run Code Online (Sandbox Code Playgroud)
result.out 包含:
^R^Qmy_testing_string
Run Code Online (Sandbox Code Playgroud)
协议版本 libprotoc 3.6.0 和 libprotoc 2.5.0
如果需求我设置path为protoc获得进口标准协议缓冲器(protobuf的),像empty.proto和timestamp.proto在Windows和飞镖?
当protoc为然:
protoc --dart_out=grpc:lib/src/protos/generated -Iprotos protos/organization.proto --plugin=protoc-gen-dart=D:\Users\Samuel\AppData\Roaming\Pub\Cache\bin\protoc- gen-dart.bat
出现以下错误:
google/protobuf/empty.proto:找不到文件。organization.proto:未找到导入“google/protobuf/empty.proto”或有错误。organization.proto:14:27: 未定义“google.protobuf.Empty”。
在插件上的IntelliJ 中Settings,定义了标准原型 (*.proto) 的位置:Protobuf Supportpath
此外,这path是在 IntelliJ 中定义的Project Structure\ Global Libraries:
organization.proto导入google/protobuf/empty.proto使用Empty类的代码:
syntax = "proto3";
package auge.protobuf;
import "google/protobuf/empty.proto";
service OrganizationService {
rpc GetOrganizations (google.protobuf.Empty) returns (OrganizationsResponse) {}
}
Run Code Online (Sandbox Code Playgroud)
IntelliJ 分析器识别出IDEA 上的import "google/protobuf/empty.proto"和Empty类,但protoc找不到。
环境是:
我正在尝试构建一个简单的容器,它从发布页面(https://github.com/protocolbuffers/protobuf/releases/tag/v3.13.0)下载 Protocol Buffers 二进制文件并将其添加到路径中。按照http://google.github.io/proto-lens/installing-protoc.html上的 Linux 说明,我尝试了以下操作Dockerfile:
FROM golang:alpine
# Install protoc (cf. http://google.github.io/proto-lens/installing-protoc.html)
RUN apk add curl
ENV PROTOC_ZIP=protoc-3.13.0-linux-x86_64.zip
RUN curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.13.0/$PROTOC_ZIP \
&& unzip -o $PROTOC_ZIP -d /usr/local bin/protoc \
&& unzip -o $PROTOC_ZIP -d /usr/local 'include/*' \
&& rm -f $PROTOC_ZIP
Run Code Online (Sandbox Code Playgroud)
问题是如果我使用构建它
docker build --tag docker-protoc .
Run Code Online (Sandbox Code Playgroud)
并在其中运行 shell,我收到错误protoc: not found,即使二进制文件位于/usr/local/bin其中PATH:
> docker run -it docker-protoc /bin/ash
/go # protoc
/bin/ash: protoc: not found
/go …Run Code Online (Sandbox Code Playgroud) 与 protoc-gen-go 相同的症状:无法确定“simple.proto”的 Go 导入路径
\n\n\n对于具有以下内容的简单原型文件。
\nRun Code Online (Sandbox Code Playgroud)\nsyntax="proto3";\n\npackage main;\n\nmessage Person {\n string name = 1;\n int32 age = 2; \n}\n我正在尝试使用 protoc 为其生成 go 代码。我跑:
\nRun Code Online (Sandbox Code Playgroud)\nprotoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative simple.proto\n我收到以下错误:
\nRun Code Online (Sandbox Code Playgroud)\nprotoc-gen-go: unable to determine Go import path for "simple.proto"\n\nPlease specify either:\n \xe2\x80\xa2 a "go_package" option in the .proto source file, or\n \xe2\x80\xa2 a "M" argument on the command line.\n
那里的所有答案都集中在第一个选项 - 添加a "go_package" option in the …
protoc ×10
go ×3
grpc ×3
python ×2
tensorflow ×2
c++ ×1
dart ×1
docker ×1
grpc-go ×1
http ×1
linux ×1
protobuf.js ×1
protobufjs ×1