protocol-buffers

Google protocol buffers compare

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 21:13:49
I want to compare two Messages or (two sub parameters) of Google protocol buffers . I don't find an API to achieve it. Any ideas? Amiga You can use the class google::protobuf::util::MessageDifferencer for this. I think it's only available since v3.0.2 : Introduced new utility functions/classes in the google/protobuf/util directory: MessageDifferencer: compare two proto messages and report their differences. MessageDifferencer::Equals(msg1, msg2); Lorenz Winkler Instead of using message.DebugString you could also do std::string strMsg; message.SerializeToString(&strMsg); with both messages and

CMake and FindProtobuf

与世无争的帅哥 提交于 2019-11-28 20:36:28
问题 I'm using the FindProtobuf module in a project where the protocol buffer files are in a sub-directory. I want the CMakeLists.txt file in that sub-directory to invoke protoc to generate the CPP Files. My project folder structure is like this: cammy/CMakeLists.txt # Root CMakeLists.txt cammy/protofiles/test.proto # protofile cammy/protofiles/CMakeLists.txt I have the include(FindProtobuf), the find_package invocation and the call to PROTOBUF_GENERATE_CPP in the CMakeLists.txt file in protobuf

Dictionary in protocol buffers

旧城冷巷雨未停 提交于 2019-11-28 20:25:46
Is there any way to serialize a dictionary using protocol buffers, or I'll have to use Thrift if I need that? People typically write down the dictionary as a list of key-value pairs, and then rebuild the dictionary on the other end. message Pair { optional string key = 1; optional string value = 2; } message Dictionary { repeated Pair pairs = 1; } For future answer seekers, ProtoBuf now supports Maps natively: message MapMessage { map<string, string> MyMap = 1; } You can check the ProtoText package. Assume you want to serialize a dict person_dict to a pre-defined PersonBuf protobuf object

gRPC + Image Upload

三世轮回 提交于 2019-11-28 19:36:24
I want to create a simple gRPC endpoint which the user can upload his/her picture. The protocol buffer declaration is the following: message UploadImageRequest { AuthToken auth = 1; // An enum with either JPG or PNG FileType image_format = 2; // Image file as bytes bytes image = 3; } Is this approach of uploading pictures (and recieving pictures) still ok regardless of the warning in the gRPC documentation? And if not, is the better approach (standard) to upload pictures using the standard form and storing the image file location instead? For large binary transfers, the standard approach is

What is the correct Protobuf content type?

拥有回忆 提交于 2019-11-28 19:28:12
问题 JSON has application/json as a standard. For protobuf some people use application/x-protobuf, but I saw something as odd as application/vnd.google.protobuf being proposed. Do we have an RFC or some other standard that I can use as a reference for this? 回答1: There's an expired IETF proposal that suggests application/protobuf . It does not address the question how the receiving side could determine the particular message type. Previous discussions suggested using a parameter to specify package

Automatically generate Java from .proto with maven/m2e in Eclipse IDE

风流意气都作罢 提交于 2019-11-28 19:01:04
For my team, I'd like to configure maven/eclipse build to automatically generate Java code from *.proto files (in a project that uses gRPC ). Currently one needs to run mvn generate-source or mvn protobuf:compile (as in plugin usage page ). Or what is the same add Run configuration to invoke maven goal compile . Whenever Eclipse Maven project is refreshed ( Alt + F5 ) or IDE is restarted, project is rebuilt but without what should appear in target/generated , thus turning project into red. So one need to generate and refresh project ( F5 ). UPDATE Eclipse has needed source folders configured

What does the ProtoInclude attribute mean (in protobuf-net)

↘锁芯ラ 提交于 2019-11-28 18:49:23
In the ProtoBuf-Net implementation, what does the ProtoInclude attribute mean, and what does it do? An example would be appreciated. I saw it in this post and I'm not sure what it does. The example was: [Serializable, ProtoContract, ProtoInclude(50, typeof(BeginRequest))] abstract internal class BaseMessage { [ProtoMember(1)] abstract public UInt16 messageType { get; } } [Serializable, ProtoContract] internal class BeginRequest : BaseMessage { [ProtoMember(1)] public override UInt16 messageType { get { return 1; } } } Also, is there a way to generate such inheritance using the protogen tool?

Is there a standard mapping between JSON and Protocol Buffers?

夙愿已清 提交于 2019-11-28 18:41:14
From a comment on the announcement blog post : Regarding JSON: JSON is structured similarly to Protocol Buffers, but protocol buffer binary format is still smaller and faster to encode. JSON makes a great text encoding for protocol buffers, though -- it's trivial to write an encoder/decoder that converts arbitrary protocol messages to and from JSON, using protobuf reflection. This is a good way to communicate with AJAX apps, since making the user download a full protobuf decoder when they visit your page might be too much. It may be trivial to cook up a mapping, but is there a single "obvious"

Google Protocol Buffers - Storing messages into file

允我心安 提交于 2019-11-28 17:12:55
I'm using google protocol buffer to serialize equity market data (ie. timestamp, bid,ask fields). I can store one message into a file and deserialize it without issue. How can I store multiple messages into a single file? Not sure how I can separate the messages. I need to be able to append new messages to the file on the fly. I would recommend using the writeDelimitedTo(OutputStream) and parseDelimitedFrom(InputStream) methods on Message objects. writeDelimitedTo writes the length of the message before the message itself; parseDelimitedFrom then uses that length to read only one message and

How to define an optional field in protobuf 3

痴心易碎 提交于 2019-11-28 16:35:05
问题 I need to specify a message with an optional field in protobuf (proto3 syntax). In terms of proto 2 syntax, the message I want to express is something like: message Foo { required int32 bar = 1; optional int32 baz = 2; } From my understanding "optional" concept has been removed from syntax proto 3 (along with required concept). Though it is not clear the alternative - using the default value to state that a field has not been specified from the sender, leaves an ambiguity if the default value