protocol-buffers

Why required and optional is removed in Protocol Buffers 3

不想你离开。 提交于 2019-11-27 16:45:29
I'm recently using gRPC with proto3 , and I've noticed that required and optional has been removed in new syntax. Would anyone kindly explain why required/optional are removed in proto3? Such kind of constraints just seem necessary to make definition robust. syntax proto2: message SearchRequest { required string query = 1; optional int32 page_number = 2; optional int32 result_per_page = 3; } syntax proto3: syntax = "proto3"; message SearchRequest { string query = 1; int32 page_number = 2; int32 result_per_page = 3; } The usefulness of required has been at the heart of many a debate and flame

how do has_field() methods relate to default values in protobuf?

假如想象 提交于 2019-11-27 15:41:10
问题 I'm trying to determine the relationship between default values and the has_foo() methods that are declared in various programmatic interfaces. In particular, I'm trying to determine under what circumstances (if any) you can "tell the difference" between a field explicitly set to the default value, and an unset value. If I explicitly set a field (e.g. "Bar.foo") to its default value (e.g., zero), then is Bar::has_foo() guaranteed return true for that data structure? (This appears to be true

Protobuf: Will set_allocated_* delete the allocated object?

最后都变了- 提交于 2019-11-27 15:34:51
问题 I have this small protobuf code (simplified, only the necessary is contained): message ParamsMessage { required int32 temperature = 1; } message MasterMessage { enum Type { GETPARAMS = 1; SENDPARAMS = 2;} required Type type = 1; optional ParamsMessage paramsMessage = 2; } I now create a MasterMessage in the following way: ParamsMessage * params = new ParamsMessage(); params->set_temperature(22); MasterMessage master; master.set_type(MasterMessage::SENDPARAMS); master.set_allocated

Undefined reference to google::protobuf::internal::empty_string_[abi:cxx11]

最后都变了- 提交于 2019-11-27 14:39:34
I'm trying to build simple test application with Protocol Buffers 2.6.1 and GNU GCC 5.1.0 (on Ubuntu 14.10) and I get following errors: /home/ragnar/cpp-tools/gcc-linux/bin/g++ -c "/home/ragnar/cpp-projects/gprotobuf_test/main.cpp" -g -O0 -Wall -o ./Debug/main.cpp.o -I. -I/home/ragnar/cpp-tools/libs/linux64/protobuf/include -I. /home/ragnar/cpp-tools/gcc-linux/bin/g++ -c "/home/ragnar/cpp-projects/gprotobuf_test/messages.pb.cc" -g -O0 -Wall -o ./Debug/messages.pb.cc.o -I. -I/home/ragnar/cpp-tools/libs/linux64/protobuf/include -I. /home/ragnar/cpp-tools/gcc-linux/bin/g++ -o ./Debug/gprotobuf

Protobuf to json in python

被刻印的时光 ゝ 提交于 2019-11-27 12:41:41
问题 I have an object that I de-serialize using protobuf in Python. When I print the object it looks like a python object, however when I try to convert it to json I have all sorts of problems. For example, if I use json.dumps() I get that the object (the generated code from protoc) does not contain a _ dict _ error. If I use jsonpickle I get UnicodeDecodeError: 'utf8' codec can't decode byte 0x9d in position 97: invalid start byte . Test code below is using jsonpickle with the error shown above.

raw decoder for protobufs format

好久不见. 提交于 2019-11-27 12:27:04
I'd like to find a way to convert a binary protobuf message into a human readable description of the contained data, without using the .proto files. The background is that I have a .proto message that it being rejected by the parser on Android, but it's not entirely clear why. I could go through the message by hand, but it's rather tedious. I tried protoc --decode_raw , but it just gives the error "Failed to parse input.". I google hoping/expecting someone would have done a nice web utility that might do this, but haven't found anything obvious. I'm just hoping to get some output like: field 1

Deserialize unknown type with protobuf-net

荒凉一梦 提交于 2019-11-27 12:07:40
I have 2 networked apps that should send serialized protobuf-net messages to each other. I can serialize the objects and send them, however, I cannot figure out how to deserialize the received bytes . I tried to deserialize with this and it failed with a NullReferenceException. // Where "ms" is a memorystream containing the serialized // byte array from the network. Messages.BaseMessage message = ProtoBuf.Serializer.Deserialize<Messages.BaseMessage>(ms); I am passing a header before the serialized bytes that contains message type ID, which I can use in a giant switch statement to return the

C++ Serialization Performance

南笙酒味 提交于 2019-11-27 11:42:43
I'm building a distributed C++ application that needs to do lots of serialization and deserialization of simple data structures that's being passed between different processes and computers. I'm not interested in serializing complex class hierarchies, but more of sending structures with a few simple members such as number, strings and data vectors. The data vectors can often be many megabytes large. I'm worried that text/xml-based ways of doing it is too slow and I really don't want to write this myself since problems like string encoding and number endianess can make it way more complicated

Is there a standard mapping between JSON and Protocol Buffers?

旧时模样 提交于 2019-11-27 11:37:26
问题 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

What does the protobuf text format look like?

独自空忆成欢 提交于 2019-11-27 10:55:02
Google Protocol Buffers can not only be serialized in binary format, also be serialized as text . However I can't easily find examples of such text; what would it look like? Expected answer: an example covering all features allowed by the protobuf IDL/proto file including a sample protobuf packet in textual form. Done myself: test.proto enum MyEnum { Default = 0; Variant1 = 1; Variant100 = 100; } message Test { required string f1 = 1; required int64 f2 = 2; repeated uint64 fa = 3; repeated int32 fb = 4; repeated int32 fc = 5 [packed = true]; repeated Pair pairs = 6; optional bytes bbbb = 7;