草庐IT

Protobuf3

全部标签

arrays - 如何将 JSON 数组建模为 protobuf 定义

我正在使用protobuf在golang中编写一个新服务。我想在.proto文件中对以下请求JSON进行建模。[{"var":["myVariable1","myVariable2"],"key1":123123,"key2":1122,"key3":"abcd-0101"},{"var":["myVariable1"],"key1":123124,"key2":1123,"key3":"abcd-0102"},]目前有两个问题:事先不知道每个数组元素中的键,因此我无法在.proto文件中创建消息并使其重复。我需要保留它的map我无法为json建模,它只是一个没有键的数组。每次我这样做

go - makefile 中的 protoc 以构建 protobuf

我已经像https://github.com/google/protobuf/blob/master/src/README.md上的教程一样安装了ProtocolBuffer之后我想构建protobuf并使用如下命令安装go库:goget-ugithub.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gatewaygoget-ugithub.com/grpc-ecosystem/grpc-gateway/protoc-gen-swaggergoget-ugithub.com/golang/protobuf/protoc-gen-goma

go - 使用 Go 工具编译 Protobuf

有没有什么好的方法可以将protobuf编译与gobuild命令集成? 最佳答案 goprotobuf“以库和协议(protocol)编译器插件的形式为Google的ProtocolBuffer提供Go支持”。README在goprotobuf图书馆有一些很好的信息。来自https://code.google.com/p/goprotobuf/source/browse/README#106:Considerfiletest.proto,containingpackageexample;enumFOO{X=17;};messageT

go - 如何在 go protobuf 中获取具体类型的 slice (不是指针)

对于原型(prototype):syntax="proto3";packagemessagepb;import"github.com/gogo/protobuf/gogoproto/gogo.proto";option(gogoproto.marshaler_all)=true;option(gogoproto.sizer_all)=true;option(gogoproto.unmarshaler_all)=true;option(gogoproto.goproto_getters_all)=false;serviceKV{//Putputsthegivenkeyintothesto

go - 有没有办法在 golang 中自定义 Marshaling Protobuf?

有没有一种方法可以像encoding/json为custommarshal/unmarshaljson提供方法一样自定义marshal/unmarshalprotobuf?在戈朗? 最佳答案 更新:proto3go库(https://google.golang.org/protobuf/proto)不再支持自定义编码。弃用:GoDoc提到Marshaler和Unmarshaler接口(interface)。typeMarshalerinterface{Marshal()([]byte,error)}typeUnmarshalerin

json - "google/protobuf/struct.proto"是通过 GRPC 发送动态 JSON 的最佳方式吗?

我写了一个简单的GRPC服务器和一个调用服务器的客户端(都在Go中)。请告诉我使用golang/protobuf/struct是否是使用GRPC发送动态JSON的最佳方式。在下面的示例中,我之前将Details创建为map[string]interface{}并将其序列化。然后我将它作为bytes在protoMessage中发送,并在服务器端反序列化消息。这是最好/最有效的方法还是我应该在我的原型(prototype)文件中将Details定义为一个结构?下面是User.proto文件syntax="proto3";packagemessages;import"google/proto

go - 为 protobuf 扩展指定 JSON 名称

我已将扩展消息添加到消息中,需要将其编码为json。但是,扩展消息的字段名称是[message.extension_message_name]。我希望它只被命名为extension_message_name,没有大括号和前缀,因为这个扩展消息存在于我们API的其他地方,而且这个奇怪的名字会增加混淆。据我所知,负责的代码在protobuf/jsonpb中,其中JSONName设置为fmt.Sprintf("[%s]",desc.Name并且似乎无法覆盖。有人对此有解决方法吗? 最佳答案 根据languageguide:Messagef

c++ - C++ 中 protobuf 消息的长度前缀

我正在使用protobuf序列化我通过C++中的套接字连接发送的消息。对于通信,我想在消息中添加一个header,指示消息的长度。你怎么看这个实现?我做了一些研究,这就是我总结的结果。有没有更好的方法来做到这一点?这个实现会引起任何麻烦吗?我知道有对Java的API支持,但不幸的是不支持C++。boolsend_message(intsocket,my_protobuf::Messagemessage){google::protobuf::uint32message_length=message.ByteSize();intprefix_length=sizeof(message_le

c++ - Qt + protobuf,类型?

我想深入了解Google在Qt开发中的ProtocolBuffer,但我无法弄清楚如何最好地整合它们。最终,我想使用ProtocolBuffer发送QUdpSocket和QTcpSocket。在ProtocolBuffermessage到通过套接字(QByteArray)发送数据然后在另一端再次返回之间的最佳方法是什么? 最佳答案 从protobuf对象创建QByteArray:Personperson;//aprotobufobjectperson.set_id(123);person.set_name("Bob");person

c++ protobuf : how to iterate through fields of message?

我是protobuf的新手,但我的任务很简单:我需要遍历消息字段并检查它的类型。如果类型是消息,我将递归地对此消息执行相同的操作。例如,我有这样的消息:packageMyTool;messageConfiguration{requiredGloablSettingsglobalSettings=1;optionalstringoption1=2;optionalint32option2=3;optionalbooloption3=4;}messageGloablSettings{requiredbooloption1=1;requiredbooloption2=2;requiredbo