2D array in proto file for C++ grpc

2,269 views
Skip to first unread message

Anirudh Kasturi

unread,
Mar 9, 2017, 2:02:30 PM3/9/17
to grpc.io
Hello folks,

I have a 2D array emulation in my proto file.

In C++, after generating the protobuf files,  I see I have methods declared for adding "columns" (add_columns) in the pb.h  without any parameters.  Also there is another method declared to add "records" (add_records) in the pb.h without any parameters.  

In Java the generated functions accept message builder as a parameter and it is easy to construct the request.

In C++ for fields in proto file with standard datatypes like string and int I have setters that accept the string and int as parameters.  For type google.protobuf.Value or type Record, I have no parameters. 

Here is the code.  How can I populate the request with the "columns" values of type google.protobuf.Value and "records" values of type Record?  Any help is appreciated.  Thank you !

message DataMessage {

        int32 Status = 1;

        int32 Entries = 2;

        repeated string columnNames = 4;


        // By repeating this message, we somewhat emulate a 2D array

        message Record {

                repeated google.protobuf.Value columns = 1;

        }

        repeated Record records = 5;

}


 

Eric Gribkoff

unread,
Mar 14, 2017, 7:16:46 PM3/14/17
to Anirudh Kasturi, grpc.io
If I'm understanding your question correctly, you are asking about setting nested message values in a proto using the C++ API. The protobuf documentation provides an example of doing this at https://developers.google.com/protocol-buffers/docs/cpptutorial#writing-a-message.



--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/8da02464-6e75-43d1-90f8-ba8ff97cc515%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Anirudh Kasturi

unread,
Mar 17, 2017, 2:16:02 AM3/17/17
to Eric Gribkoff, grpc.io
Thanks a lot Eric ! Yes I saw this example before, but after your email, when I again looked at it, things made a lot of sense.  

Best,
Anirudh
Reply all
Reply to author
Forward
0 new messages