Rebecca Joy | 10 Feb 21:11 2016
Picon

Protobuf SetString GetString GetStringReference segfault

I am working with protobuf to create a system which supports a number of different messages, and I am relying on the dynamic messages, factory, and reflection interface. I can get and set all of the different field data types (uint32, int64, ... etc.) except the string type. When I try to use any of the getters or setters for a field with a string data type, my code segfaults. The first chunk of code is the minimal example (sorry it's so long, but the importer, factory, etc. needs to be in place for it to make sense). The second chunk of code is the proto file that I have been using for testing. My question is how do I access the string field to either set or get the data.

#include <vector>
#include <string>
#include <sstream>
#include <dirent.h>
#include <stdexcept>
#include <iostream>

#include <google/protobuf/message.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/io/tokenizer.h>
#include <google/protobuf/compiler/parser.h>
#include <google/protobuf/descriptor_database.h>
#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/compiler/importer.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/arena.h>

class errCollector : public google::protobuf::compiler::MultiFileErrorCollector
{
public:
   
~errCollector() {};
   
void AddError(const std::string& filename,
                 
int line, int column, const std::string& message) {};
};

google
::protobuf::compiler::Importer* createImporter( );
void buildSubMessages(const google::protobuf::Descriptor* desc,
                      google
::protobuf::Message* msg, const google::protobuf::Reflection* ref,
                      google
::protobuf::DynamicMessageFactory* factory);

int main(int argc, char** argv)
{

   
// Usage: ProtobufMinimalExample <message type name>
    std
::string msgType(argv[1]);

   
// Error message stream
    std
::ostringstream msgStream;

   
// Create the importer object which holds all of the .proto files.
    google
::protobuf::compiler::Importer* importer = createImporter();
   
// Create the descriptor pool which holds all of the message descriptors.
   
const google::protobuf::DescriptorPool* pool(importer->pool());
   
// Create an object to hold the top-level message.
    google
::protobuf::Message* mutableMsg;
   
// Create an object to hold the top-level message descriptor.
   
const google::protobuf::Descriptor* messageDesc;
   
// Create a message to hold the prototype description of the dynamic message
   
const google::protobuf::Message* protoTypeMsg;
   
// Create the message factory.
    google
::protobuf::DynamicMessageFactory* factory( new google::protobuf::DynamicMessageFactory);

    messageDesc
= pool->FindMessageTypeByName(msgType);
    protoTypeMsg
= factory->GetPrototype(messageDesc);
    mutableMsg
= protoTypeMsg->New();

   
// Get a submessage in the field named "yellow".
   
const google::protobuf::FieldDescriptor* field = messageDesc->FindFieldByName("yellow");
   
const google::protobuf::Descriptor* subMsgDesc = field->message_type();
   
const google::protobuf::Message* subProtoTypeMsg = factory->GetPrototype(subMsgDesc);
    google
::protobuf::Message* subMutableMsg = subProtoTypeMsg->New();
   
const google::protobuf::Reflection* subReflection = (subMutableMsg->GetReflection());
   
const google::protobuf::Descriptor* subMutableDesc = subMutableMsg->GetDescriptor();

    std
::string* name = new std::string();

   
// Segfault
   
//const google::protobuf::FieldDescriptor* subField = subMutableDesc->FindFieldByName("name");
   
//subReflection->SetString(mutableMsg, subField, "Hello");
   
//subReflection->GetString(*(mutableMsg), subField);
   
//subReflection->GetStringReference(*(mutableMsg), subField, name);

   
// Works
   
//const google::protobuf::FieldDescriptor* subField = subMutableDesc->FindFieldByName("score");
   
//subReflection->SetUInt32(mutableMsg, subField, 9);
   
//subReflection->GetUInt32(*(mutableMsg), subField);

   
return 0;
}

google
::protobuf::compiler::Importer* createImporter()
{
    google
::protobuf::compiler::DiskSourceTree srcTree;
    errCollector error
;
    google
::protobuf::compiler::Importer* fdProtoImporter(new google::protobuf::compiler::Importer(&srcTree, &error));
   
const char* protoFilePath = "./proto";

   
struct dirent* entry;
    DIR
* dp;
    std
::vector<std::string> importProtoFilenames;

    dp
= opendir(protoFilePath);

   
unsigned char isFile = 0x8;
   
while( (entry = readdir(dp)) )
   
{
       
if(entry->d_type != isFile)
           
continue;
        importProtoFilenames
.push_back(std::string(entry->d_name));
   
}
    closedir
(dp);

    srcTree
.MapPath("", protoFilePath);

   
for( auto protoFilename : importProtoFilenames )
   
{
       
if(fdProtoImporter->Import(protoFilename) == NULL)
       
{
           
continue;
       
}
   
}
   
return std::move(fdProtoImporter);
}

message SSL_Referee {

required uint64 packet_timestamp
= 1;

enum Stage {
    NORMAL_FIRST_HALF_PRE
= 0;
    NORMAL_FIRST_HALF
= 1;
    NORMAL_HALF_TIME
= 2;
    NORMAL_SECOND_HALF_PRE
= 3;
    NORMAL_SECOND_HALF
= 4;
    EXTRA_TIME_BREAK
= 5;
    EXTRA_FIRST_HALF_PRE
= 6;
    EXTRA_FIRST_HALF
= 7;
    EXTRA_HALF_TIME
= 8;
    EXTRA_SECOND_HALF_PRE
= 9;
    EXTRA_SECOND_HALF
= 10;
    PENALTY_SHOOTOUT_BREAK
= 11;
    PENALTY_SHOOTOUT
= 12;
    POST_GAME
= 13;
}
required
Stage stage = 2;

optional sint32 stage_time_left
= 3;

// These are the "fine" states of play on the field.
enum Command {
   
// All robots should completely stop moving.
    HALT
= 0;
   
// Robots must keep 50 cm from the ball.
    STOP
= 1;
   
// A prepared kickoff or penalty may now be taken.
    NORMAL_START
= 2;
   
// The ball is dropped and free for either team.
    FORCE_START
= 3;
   
// The yellow team may move into kickoff position.
    PREPARE_KICKOFF_YELLOW
= 4;
   
// The blue team may move into kickoff position.
    PREPARE_KICKOFF_BLUE
= 5;
   
// The yellow team may move into penalty position.
    PREPARE_PENALTY_YELLOW
= 6;
   
// The blue team may move into penalty position.
    PREPARE_PENALTY_BLUE
= 7;
   
// The yellow team may take a direct free kick.
    DIRECT_FREE_YELLOW
= 8;
   
// The blue team may take a direct free kick.
    DIRECT_FREE_BLUE
= 9;
   
// The yellow team may take an indirect free kick.
    INDIRECT_FREE_YELLOW
= 10;
   
// The blue team may take an indirect free kick.
    INDIRECT_FREE_BLUE
= 11;
   
// The yellow team is currently in a timeout.
    TIMEOUT_YELLOW
= 12;
   
// The blue team is currently in a timeout.
    TIMEOUT_BLUE
= 13;
   
// The yellow team just scored a goal.
   
// For information only.
   
// For rules compliance, teams must treat as STOP.
    GOAL_YELLOW
= 14;
   
// The blue team just scored a goal.
    GOAL_BLUE
= 15;
}
required
Command command = 4;

// The number of commands issued since startup (mod 2^32).
required uint32 command_counter
= 5;

// The UNIX timestamp when the command was issued, in microseconds.
// This value changes only when a new command is issued, not on each packet.
required uint64 command_timestamp
= 6;

// Information about a single team.
message
TeamInfo {
   
// The team's name (empty string if operator has not typed anything).
    required
string name = 1;
   
// The number of goals scored by the team during normal play and overtime.
    required uint32 score
= 2;
   
// The number of red cards issued to the team since the beginning of the game.
    required uint32 red_cards
= 3;
   
// The amount of time (in microseconds) left on each yellow card issued to the team.
   
// If no yellow cards are issued, this array has no elements.
   
// Otherwise, times are ordered from smallest to largest.
    repeated uint32 yellow_card_times
= 4 [packed=true];
   
// The total number of yellow cards ever issued to the team.
    required uint32 yellow_cards
= 5;
   
// The number of timeouts this team can still call.
   
// If in a timeout right now, that timeout is excluded.
    required uint32 timeouts
= 6;
   
// The number of microseconds of timeout this team can use.
    required uint32 timeout_time
= 7;
   
// The pattern number of this team's goalie.
    required uint32 goalie
= 8;
}

// Information about the two teams.
required
TeamInfo yellow = 7;
required
TeamInfo blue = 8;
}

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+unsubscribe <at> googlegroups.com.
To post to this group, send email to protobuf <at> googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
Josh Humphries | 10 Feb 16:55 2016
Gravatar

Unhelpful compiler warning when a file has no syntax declaration

The protoc compiler emits a warning message whenever it encounters a proto file that has no syntax level declared. But the warning doesn't indicate the filename. I'd like our builds to be warning-free. But with a make task that builds lots of protos at once, it's a total nuisance to find the offending file. The protoc compiler really should just indicate the name of the file in the warning.

I opened a pull request a few days ago to fix this:
It hasn't gotten any attention.

What's the best policy for trying to submit changes? Should I start a discussion on this group first, to give visibility to it? Or is there some time window I should allow (few days?) before expecting any attention/comments on a pull request?

Thanks in advance.

----
Josh Humphries
Manager, Shared Systems  |  Platform Engineering
Atlanta, GA  |  678-400-4867

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+unsubscribe <at> googlegroups.com.
To post to this group, send email to protobuf <at> googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
Bruce | 10 Feb 00:01 2016
Picon

Third Party Add ons: ProtoBufEditor - Editor for Protocol Buffers Messages


The Listing for My project protobufeditor (Editor for Protocol Buffers Messages) is listed on

 https://github.com/google/protobuf/wiki/Third-Party-Add-ons#Other_Utilities page under Editor for serialized protobufs

currently it points to the old Project page: https://code.google.com/archive/p/protobufeditor/

could you please update this to the new Project Page:


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+unsubscribe <at> googlegroups.com.
To post to this group, send email to protobuf <at> googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
Brian | 9 Feb 23:58 2016
Picon

Instructed to "download a pre-built binary from our release page" : contains no pre-built binaries

On the main protobuf github page it says that for "non-C++ users, the simplest way to install the protocol compiler is to download a pre-built binary from our release page". For the latest release there is no protoc binary provided. As a Java developer I would prefer not to have to install the C++ build chain tools just to use the protocol buffers compiler.

The current releases seem to contradict these instructions, but maybe this means that after I build the binaries myself they are then pre-built?

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+unsubscribe <at> googlegroups.com.
To post to this group, send email to protobuf <at> googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
Tanweer Alam | 9 Feb 06:52 2016
Picon

ParseFromArray for Data Deserialization

Hi All,
I have a situation in which I have the serialized array and I only require the bare minimum part of protobuf so that I am able to deserialize the serialized array.
Do we have a  defined way for achieving this or do I need to pick up classes and use it in my code to do this.

TIA 
tanweer

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+unsubscribe <at> googlegroups.com.
To post to this group, send email to protobuf <at> googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
Tamás Kenéz | 9 Feb 18:08 2016
Picon

What tool does the protobuf project use to generate ref manual from c++ headers?

What tool does the protobuf project use to generate ref manual from c++ headers?
I see there is almost no markup noise. Is the tool publicly available?
Thanks, Tamas

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+unsubscribe <at> googlegroups.com.
To post to this group, send email to protobuf <at> googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
Tanweer Alam | 9 Feb 06:41 2016
Picon

Minimal Protobuf for deserializing from SerializedArray

Hi,
I have a situation in which I specifically require only Deserialize From serializedArray functionality. I already have the serialized data.. Is it possible (any defined way) in which I can have portion of protobuf library instead of full libprotobuf or do I need pick classes from full source and use it.

TIA 
tanweer

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+unsubscribe <at> googlegroups.com.
To post to this group, send email to protobuf <at> googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
Tom Ball | 9 Feb 17:38 2016
Picon
Gravatar

Public protobuf demo server?

Does anyone know of a public server that uses protocol buffers to communicate with its clients? I'm writing a tutorial for one of those clients, and demos feel more real if there is actual client-server communication.

If not, anyone have ideas for a simple demo server? An address book came to mind first, but it would have to be read-only or it would soon be full of garbage entries.

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+unsubscribe <at> googlegroups.com.
To post to this group, send email to protobuf <at> googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
Tim Kientzle | 27 Jan 06:22 2016
Picon

Fwd: Protobuf question for mailing list


I’m trying to implement Any, including proper JSON and protobuf encoding, and the following scenario has me stumped:

I’m looking at the any.proto file, which includes this example:

Sample proto file:
//     package google.profile;
//     message Person {
//       string first_name = 1;
//       string last_name = 2;
//     }

Resulting JSON encoding:
//     {
//       " <at> type": "type.googleapis.com/google.profile.Person",
//       "firstName": <string>,
//       "lastName": <string>
//     }

The scenario I’m trying to understand involves three systems:

Originating system:
* Knows google.profile and writes out the JSON above

Middle system:
* Reads the JSON example above
* Does *not* know google.profile (doesn’t have the descriptor and has no way to get it)
* Writes out protobuf

Receiving system:
* Knows google.profile and reads the protobuf

In particular:  What is the protobuf serialization between the middle and receiving systems?

Without the descriptor, the middle system cannot poduce the “real" protobuf binary format (the field numbers aren’t in that format), so the only option would seem to be to serialize the JSON data as a protobuf Struct representation (which in turn has interesting implications for the receiving system). Am I missing some other option?

Tim

P.S.  Nice work on the conformance test suite, by the way!  That clarified a *lot* of details about the expected handling for protobuf JSON format.


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+unsubscribe <at> googlegroups.com.
To post to this group, send email to protobuf <at> googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
kevin chaves | 4 Feb 13:59 2016
Picon

Questions about Services

Hi, 

I'm completely new to using protocol buffers and there are some things that aren't very clear. I may be missing something very simple but the documentation says the simple services are being deprecated so you have to turn them on using option cc_generic_services = false;. What is the replacement for this in 3+? I did some digging and it looks like gRPC is a plugin that can also be used to generate code but I'd like to avoid that because it says it's still development builds. Are plugins the only options now?

Should I still be using the simple services?

How well does gRPC work? Is there anything I should be concerned about implementing C# client proxy and C++ server? Is that even possible?

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+unsubscribe <at> googlegroups.com.
To post to this group, send email to protobuf <at> googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
Vishal Singh | 4 Feb 12:58 2016
Picon

Unable to get through error: Protocol message contained an invalid tag (zero).

Hi,

I am building an application using Sitewhere in which the message exchange between device and the server is done using Protocol Buffer format. The server sends a command to the device after converting the message in this format, but at the device end when the bytes array is converted to get the command, following exception is thrown:

 com.google.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero).
     at com.google.protobuf.CodedInputStream.readTag(CodedInputStream.java:108)
     at com.sitewhere.android.generated.Android$AndroidSpecification$_Header.<init>(Android.java:212)
     at com.sitewhere.android.generated.Android$AndroidSpecification$_Header.<init>(Android.java:203)
     at com.sitewhere.android.generated.Android$AndroidSpecification$_Header$1.parsePartialFrom(Android.java:255)
     at com.sitewhere.android.generated.Android$AndroidSpecification$_Header$1.parsePartialFrom(Android.java:1)
     at com.google.protobuf.AbstractParser.parsePartialFrom(AbstractParser.java:200)
     at com.google.protobuf.AbstractParser.parsePartialDelimitedFrom(AbstractParser.java:241)
     at com.google.protobuf.AbstractParser.parseDelimitedFrom(AbstractParser.java:253)
     at com.google.protobuf.AbstractParser.parseDelimitedFrom(AbstractParser.java:259)
     at com.google.protobuf.AbstractParser.parseDelimitedFrom(AbstractParser.java:49)
     at com.sitewhere.android.generated.Android$AndroidSpecification$_Header.parseDelimitedFrom(Android.java:410)
     at com.sitewhere.android.example.SiteWhereExample.onReceivedCustomCommand(SiteWhereExample.java:273)
     at com.sitewhere.android.SiteWhereActivity$SiteWhereResponseProcessor.receivedCustomCommand(SiteWhereActivity.java:231)
     at com.sitewhere.android.mqtt.RegistrationManager.onCustomCommandReceived(RegistrationManager.java:112)
     at com.sitewhere.android.mqtt.DefaultMqttInteractionManager$MqttMessageProcessor.run(DefaultMqttInteractionManager.java:139)
     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)

I have no clue what is the meaning of "Protocol message contained an invalid tag (zero)". Please help. The byte array received from the server is:

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+unsubscribe <at> googlegroups.com.
To post to this group, send email to protobuf <at> googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Gmane