FAQ Database Discussion Community


Protocol buffer `ParseFromString` in Java for parsing text format?

java,parsing,protocol-buffers
Is ParseFromString available in Java for protocol buffers? The C++ version has it: https://code.google.com/p/protobuf/source/browse/trunk/src/google/protobuf/text_format.h?r=32...

Should C++ classes contain or be constructed/populated from protocol buffer messages

c++,protocol-buffers
For protocol buffers in C++, I am wondering if it is better to contain a protobuf message in my class, or to have it be constructed from and populate an external protobuf message. I could not find examples describing best practices for this case. I'm particular worried about performance differences...

reserved keyword is used in protobuf in Python

python,protocol-buffers
In general, I have a protobuf definition which used a Python keyword "from". It works in Java/C#/C++, but when comes to Python, I could not assign value to it. Here is the detail of my problem. I have a protobuf definition like below: message Foo { required int64 from =...

How to use Google Protobuf Map in C++?

c++,hashmap,protocol-buffers,c++14
I am attempting to use the new protobuf Map functionality in C++. The following was done on Ubuntu 14.04 with gcc 4.9.2 C++14 and protobuf 3.0.0-alpha-4: Message definition: message TestMap { map<string,uint64> map1 = 1; } Then, I tried to compile the following example program: auto test = debug::TestMap::default_instance(); auto...

MSVS2008 to MSVS2003 Conversion (Google Protobuf)

visual-studio,converter,protocol-buffers
I have to get Google Protobuf running on Visual Studio 2003, but it was built for Visual Studio 2008. Does anyone know wether that is possible and if so, how? I did some research and found, that sometimes just renaming the projects version number in the .sln should help, but...

How to compile protocol buffers schema at runtime?

java,protocol-buffers,java-compiler-api
I can create the schema (Descriptors.Descriptor) at runtime dynamically using FileDescriptorProto, also I'm able to serialize and deserialize messages using DynamicMessage. However performance of DynamicMessage is not good enough because of the way it constructs the messages. I wonder whether it's possible to compile the schema at runtime and use...

Write a message to a given file in text mode

c++,protocol-buffers
Please give me an example how to write the message to a given file in Google protocol buffer TEXT MODE ( not binary mode). message S1 { required string name=1; required string family=2; } message S2 { repeated S1; } and how can read the text format from file if...

Deep-copying with ProtoBuf in C/C++

c++,c,protocol-buffers,protobuf-c
Say I had an array of pointers, each of which points to structs which may once again have pointers to other structs in them; is it possible to handle serializing this using protobuf? If so, how? Any help would be greatly appreciated....

Deserialize Protobuf in python from class name

python,protocol-buffers
How can I deserialize a protocol buffer message, knowing only the string name of the protoc-generated class? For some reason, the fully qualified name of the message that I get with DESCRIPTOR.full_name does not match the actual location of the python class, so I am unable to deserialize it with...

Error: 2 overloads have no legal conversion for this pointer, when protocol buffer method is invoked

c++,protocol-buffers
Could someone help me figure this error C2663: MediaSetting::mutable_mediamessage: 2 overloads have no legal conversion for this pointer happened, when mutable_mediamessage() is called in the following codes. class MediaSetting : public ::google::protobuf::Message { public: inline ::MSG::MediaMessage* mutable_mediamessage(int index); inline ::google::protobuf::RepeatedPtrField< ::MSG::MediaMessage >* mutable_mediamessage(); } inline ::MSG::MediaMessage* MediaSetting::mutable_mediamessage(int index) { return...

Problems using Protocol Buffers to read messages from file

c++,protocol-buffers
I'm trying to use Google Protocol Buffers to read multiple messages from a file. The documentation suggests using CodedInputStream. But if I try and read more than a very small message I get a failure from MergeFromCodedStream For example, if I have a message defined as: message Chunk { repeated...

Go + Protocol buffers acting really strange

go,protocol-buffers
I'm writing a service-based server for a project I'm working on, which is written in Go and uses Protocol Buffers for inter-service communication. Everything was working fine until I added protocols named DeviceRequest and DeviceResponse, now the compiler can't find them, while the go source of the protocol exists and...

protobuf-c: How to pack nested messages

c,protocol-buffers
I have a Protobuf Protocol file that looks something like this: message Foo { message Bar { required string name = 1; required string value = 2; } message Baz { required Bar a = 1; } } Given this protocol file, I need to write an encoder using protobuf-c,...

Decoding a Google protocol buffer message in javascript using ProtoBuf.js

javascript,protocol-buffers
I am trying to send a message over MQTT making use of the google protocol buffer in javascript (ProtoBuf.js) I was able to encode the message using the following code: var ProtoBuf = dcodeIO.ProtoBuf; var builder = ProtoBuf.loadProtoFile("./complex.proto"), Game = builder.build("Game"), Car = Game.Cars.Car; var car = new Car({ "model"...

VerifyError using protobuf 2.4.1

protocol-buffers
I am getting below error when trying to create a newBuilder() object for a given protobuf class. Having protobuf-java-2.4.1.jar in the classpath. Same is working on the server side but fails on the client. java.lang.VerifyError: Bad return type Exception Details: Location: packagename.QuerySpecProtos$QuerySpec$Builder.clone()Lcom/google/protobuf/AbstractMessageLite$Builder; @4: areturn Reason: Type 'packagename.QuerySpecProtos$QuerySpec$Builder' (current frame, stack[0])...

What is good practice for protobuf message of constant size?

c++,protocol-buffers
Well, I have message structure: message SomeMessage { enum MessageType { eRegisterQuery = 1; eRegisterResponse = 2; eConnectionControlQuery = 3; eConnectionControlResponce = 4; } optional uint64 beginFlag = 1; required uint32 type = 2; oneof messages { optional RegisterQuery registerQuery = 3; optional RegisterResponce registerResponce = 4; optional Control control...

Program with Protocol Buffer can't get linked

c++,compilation,linker,activemq,protocol-buffers
I have a cpp file in which I am trying to use the message that I created with protocol buffer. However I keep getting that famous "undefined reference" error as follows: undefined reference to PointMsg::PointMsg() undefined reference to PointMsg::~PointMsg() undefined reference to PointMsg::~PointMsg() Here is the proto file that I...

How to set default value to a customed google protobuf type?

protocol-buffers,default-value
I have a google protobuf structure: message ResourceProto{ optional int32 memory = 0; optional int32 core = 1; } And I have another structure: message AnotherProto{ optional ResourceProto resource = 0 [default to ResourceProto(100,1)]; .... } I know how to set default value to normal type like int, String, Bool,...

Undefined reference while linking static C library

c,linker,static-libraries,protocol-buffers,static-linking
In my latest project I am encountering a strange issue regarding an undefined reference to a method of a shared library. I searched on SO but all I could find was either C++ related (extern "C") or not really helping. The library in question is my fork of libosm which...

Protobuf repeated message option

protocol-buffers
I'm trying to append some documentation metainformation to a protobuf message by extending google.protobuf.MessageOptions. One of my metainfo option may appear more than once. Looks like I can declare repeated option but how can I use it on a message? Here is an example of what I try to achieve:...

Protobuf message object creation by name

c++,protocol-buffers
I have a lot of protobuf messages for which I currently use a manually written lookup function to generate the message by its name. Since the messages get more and more as the project evolves, I'm getting tired of maintaining this lookup code by hand. So, is there a way...

Protocol Buffer: Version Change

protocol-buffers
I have accidentally installed version 3.0.0 and most of my files naturally gave tons of errors. Now I want to take it back to 2.6.1. I already downloaded 2.6.1 and installed, however when I do protoc --version it still shows libprotoc 3.0.0, which is wrong. Is there a way to...

How to use ProtoBuf extensions to get polymorphism in C++

c++,protocol-buffers,zeromq
I am trying to define a common basic message which defines the type of the message (for easier parsing) and is then extended with the actual message. The messages will be used in an RPC way. My .proto file syntax = "proto2"; package userapi; // wrapper for commands message Command...

Protocol Buffer error C2059 under VS2008

c++,protocol-buffers
Now I have one message defined in protocol buffer message Test { enum OperationFlag { ADD = 0; DELETE = 1; } optional OperationFlag flag = 1; } After complied with protoc(version 2.5.0), the header file will be generated. However there is one error syntax error : 'constant' for the...

protoc-c: Nested structure with optional string throws seg fault

c,serialization,deserialization,protocols,protocol-buffers
Trying out Google protocol buffers for my code in C language. messagefile.proto =================== mesage othermessage { optional string otherstring = 1; } message onemessage { optional string messagestring = 1; optional int32 aninteger = 2; optional othermessage otr_message= 3; } ============================================== --> protoc-c messagefile.proto --c_out=./ this resulted in two files...

Google Protocol Buffer serialized string can contain embedded NULL characters in it?

c++,serialization,null,protocol-buffers,stdstring
I am using Google Protocol Buffer for message serialization. This is my sample proto file content. package MessageParam; message Sample { message WordRec { optional uint64 id = 1; optional string word = 2; optional double value = 3; } message WordSequence { repeated WordRec WordSeq = 1; } }...

ANDROID: How to properly link against static libraries while creating shared libraries with dependencies on the static ones

android,c++,android-ndk,shared-libraries,protocol-buffers
I have to use some c++ code in my android application. This code was used successfully in an iOS project. The code depends on 2 external libraries: zero-mq and protocol buffers. I compiled the zmq library as an static library like explained here. I added the static (.a) library and...

Endianness of protocol buffer message

c#,protocol-buffers
Background: A C++ program run on a server and outputs network data in a protocol buffer file. The data contains, among other things ip addresses and ports.The ip and port are saved as uint32 values in the file. The C++ program is running on a linux server with a intel...

Converting protocol buffers to/from JSON in C, without generating C code

c,json,protocol-buffers,protobuf-c
I need to use .desc files to enable the reading of serialized protocol-buffer messages and their conversion to JSON (using jansson). This is because the protocol-buffer message formats will change much more frequently than the C code. The .desc files will be a runtime input to the executable. I've found...

Protocol Buffers import message depending on another imported message

import,protocol-buffers
About import statement, google says that https://developers.google.com/protocol-buffers/docs/proto#services : You can use definitions from other .proto files by importing them. To import another .proto's definitions, you add an import statement to the top of your file. By default you can only use definitions from directly imported .proto files. ...Sounds great, but...

How to fix “import com.dyuproject cannot be resolved” error

java,maven,protocol-buffers,protostuff
I'm fairly new to Java and especially new to Maven and specifically the protostuff project (protostuff website). I need to use protostuff to serialize/deserialize XML to google's protobuf format. I tried using the protobuf-java-format package, but there's a documented error in deserialization that is a show-stopper for me (issue 37)....

How to encode multiple distinguishable items back to back with protobuf?

c++,protocol-buffers,googletest
So, I have a unit test where I'm trying to ensure that encoding and decoding is sound. Basically, I kind of want to be able to serialize multiple different C++ objects into a string, and then write that string into a file. This is what I have so far: Here's...

Exmples from gRPC is not working

protocol-buffers,grpc
I'm trying to run route example but when client starts to connecting to server (blockingStub.getFeature(request)) it hangs. If I stops client (ctrl+c in terminal) error occurs (look below). Does anybody knows what might be wrong? Stack trace: Terminal1-server: ./gradlew routeGuideServer :grpc-core:compileJava UP-TO-DATE :grpc-core:animalSniffer ... May 06, 2015 4:56:06 PM io.grpc.examples.routeguide.RouteGuideServer...

iOS protobuf GCDAsyncSocket

ios,netty,protocol-buffers,gcdasyncsocket,cocoaasyncsocket
I am writing a small app which requires sending protobuf message to a netty server via tcp, where CocoaAsyncSocket/GCDAsyncSocket is used. To do this, I use the following code: Message_LoginMessageRequest_Builder *msg_tmp_login_build=[Message_LoginMessageRequest builder]; [msg_tmp_login_build setPhoneNumber:input_phone.text]; [msg_tmp_login_build setEmail:input_email.text]; [msg_tmp_login_build setPassword:input_password.text]; Message_Builder *msg_tmp_build=[Message builder]; [msg_tmp_build setType:Message_MessageTypeLoginReq];...

How to determine message type in protobuf so that I can use that type.parsefrom(byte[ ])

java,protocol-buffers
I am trying to send protobuf data from cpp side to java side. I have multiple message types defined in .proto On Cpp side, I have enums for every message type and I am adding it to the buf output as follows: uint8_t* __temp = (uint8_t*)(buf); *__temp++ = (type) >>...

How to assign Google protocol buffer SerializeAsString() output which contains embedded nulls to std::string?

c++,serialization,null,protocol-buffers,stdstring
I am trying to serialize the message as string in C++ using google protocol buffer and assign the serialized result (which contains embedded nulls in it) to std::string. Following is my code: std::string result = message.SerializeAsString(); It is ignoring the characters after the first \0 character. result is not having...

How to print out the values in a protobuf message

protocol-buffers
I know there is a way to serialize a message in protobuf. But is there a easy way to print out the values in a protobuf message? Something like a toString() method in Java? Thanks....

Error working with two frameworks in Xcode

ios,xcode,frameworks,protocol-buffers
I need to work with two third party frameworks in my Xcode project but the two of them use Google's Protocol Buffer library and they were compiled against different versions of that library. Both frameworks work fine separately but when I try to use them in the same project I...

Google Protobufs in Java: How do you get a Message.Builder from a FieldDescriptor?

java,buffer,protocols,protocol-buffers
I have a FieldDescriptor for a message field defined in my protocol buffer. I want to start constructing a value for that field, but I'm stuck trying to get a Message.Builder for that FieldDescriptor. The code I'm writing is extremely generic - It's designed to serialize between MongoDB and Protocol...

Deleting an element from a Riak set via protocol buffers using the Erlang client without fetching the whole set

erlang,protocol-buffers,riak
Via the HTTP API, we can delete an arbitrary element from a set without fetching the whole content: curl -X POST http://127.0.0.1:8098/types/sets/buckets/travel/datatypes/cities -H "content-type: application/json" -d '{ "remove" : "Toronto" }' (to verify: tcpdump -i any -s 0 -n 'src port 8087 or src port 8098 and host 127.0.0.1') However...

what will be done if the buffer socket full

networking,udp,buffer,protocol-buffers
what will be done if the buffer socket full in an UDP protocol? does it replace the old data with the new one? ot it just drop the new data? In case that it's not related with UDP protocols, and it's specified in the code, how to do this in...

Protobuf cannot be linked on ubuntu

c++,ubuntu,linker,cmake,protocol-buffers
I try to use protobuf but somehow the linking fails (here just snippet): Linking CXX executable app CMakeFiles/app.dir/msg.pb.cc.o: In function `evoswarm::protobuf_AssignDesc_a_5fto_5fb_2eproto()': msg.pb.cc:(.text+0x133): undefined reference to `google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(google::protobuf::Descriptor const*, google::protobuf::Message const*, int const*, int, int, int, int, int, int)' msg.pb.cc:(.text+0x190): undefined reference to...

Can protobuf service method return primitive type?

protocol-buffers,rpc,protobuf-c
I'm trying to use Google protobuf and i 'm having the next descriptions: message.proto file: message Request { required int32 id = 1; optional string value = 2; } service.proto file: import "message.proto"; service Service { rpc request (Request) returns (bool); } I'm trying to generate c++ sources and getting...

Protocol Buffer - merge binary data files with the same .proto file to the one file

python,protocol-buffers
I have a lot of data files (almost 150) in binary structure created according the .proto scheme of Protocol Buffer. Is there any efficient solution how to merge all the files to just one big binary data file without losing any information?

gRPC/Protobuf 3 syntax: what is the difference between rpc lines that end with semicolon vs '{}'?

protocol-buffers,grpc
I've seen two different ways of declaring an gRPC service using Protobuf v3. Some code has the rpc line end with a semicolon (such as the current proto3 documentation): service SearchService { rpc Search (SearchRequest) returns (SearchResponse); } Other code has the rpc line end with {}: service Greeter {...

How to compare two proto buffer message in Java?

java,protocol-buffers
In package com.google.protobuf I found a Message interface, it claims it will compare by content: public interface Message extends MessageLite, MessageOrBuilder { // ----------------------------------------------------------------- // Comparison and hashing /** * Compares the specified object with this message for equality. Returns * <tt>true</tt> if the given object is a message of...

How to access Protocol Buffers custom option in python?

python,protocol-buffers
I'm following instructions from Google Developers guide in order to create custom message option. I have used their example but I've received an error: Traceback (most recent call last): File "test_my_opt.py", line 2, in <module> value = my_proto_file_pb2.MyMessage.DESCRIPTOR.GetOptions().Extensions[my_proto_file_pb2.my_option] File "(...)\google\protobuf\internal\python_message.py", line 1167, in __getitem__ _VerifyExtensionHandle(self._extended_message, extension_handle) File "(...)\google\protobuf\internal\python_message.py", line...

Protocol buffers negative int32/int64 encoder's specifications are fuzzy

protocol-buffers
In the encoder specs of protocol buffers https://developers.google.com/protocol-buffers/docs/encoding , it is said that : If you use int32 or int64 as the type for a negative number, the resulting varint is always ten bytes long – it is, effectively, treated like a very large unsigned integer Okay, that look nice,...

How to fully read a file with delimited messages in Google Protobufs?

java,protocol-buffers,delimited
I'm trying to read a file, which has multiple delimited messages in it (in the thousands), how can I do this properly using Google protobufs? This is how I'm writing the delimited: MyMessage myMessage = MyMessage.parseFrom(byte[] msg); myMessage.writeDelimitedTo(FileOutputStream); and this is how I'm reading the delimited file; CodedInputStream is =...

ServiceStack memcached and protobuf

servicestack,protocol-buffers
How can I use the protobuf format for serializing and deserializing data out of enyim memcached in servicestack instead of Json?

Can't use a python application, which uses the google protocol buffer

python,protocol-buffers
I am trying to use an application I found on GitHub which records live updates for public transport positions, see the following link to the instructions and application: https://github.com/mattwigway/gtfsrdb When I modify the terminal commands to: python gtfsrdb.py run -p https://gtfsrt.api.translink.com.au/Feed/SEQ.pb -d sqlite:///test.db -c I get the following error: Exception...

Wire protocol buffers vs Cap'n proto - which one is better?

android,protocol-buffers
I'm currently using wire protocol buffers in one of my android apps and looks like it's parseFrom() method is not very efficient as it takes ~10 ms even to parse a very small of data. So I came across this: https://capnproto.org/index.html Does anyone know what's the key difference between these...

How to generate BlockingStub in C++ in Protobuf?

c++,protocol-buffers
I'm having the following .proto for Protobuf (2.6.1 to be more detailed): service InstallService { rpc getWifiNetworks (WifiRequest) returns (WifiResponse); } I've generated java files and i'm having BlockingStub: TestInstallService.BlockingInterface service = TestInstallService.newBlockingStub(channel); and i can use if in blocking way (works good): Wifi.WifiResponse response = service.getWifiNetworks(controller, request); Now i'm...

Getting Unknown flag: -v when i run protoc -version in my ubuntu

protocol-buffers,ubuntu-14.04
I'm getting the following message when i run protoc -version in my ubuntu terminal. Unknown flag: -v Earlier to this, I had got the following error when I ran protoc -version. I found a solution through google and ran "sudo ldconfig /usr/local/lib". After running that, I'm getting the Unknown flag...