Nested messages using C++

4,030 views
Skip to first unread message

Linus

unread,
Jan 13, 2011, 4:48:29 PM1/13/11
to Protocol Buffers
Hello,

I have nested messages like the following (it is a little more
complicated, but i am trying to simplify with this example).

package DB;

message Header
{
required int32 ID=1;
message param
{
required int32 size_m = 1;
required int32 size_n = 2;
}
required param p = 2;
}

message data
{
repeated double = 1;
}


message DB
{
required Header = 1;
required data = 2;
}


The problem I am having is that the accessor methods generated for the
"DB " does not have a
set_param( DB::Header::param ).

Is there something wrong with how I am structuring my messages? Any
help is appreciated.
Please let me know if this post is unclear and I will try and explain
myself better.

Thanks!
Linus

Linus

unread,
Jan 13, 2011, 8:38:12 PM1/13/11
to Protocol Buffers
I am new to PB and I just ran into this. Is it possible that the PB
compiler does not generate set_<...> methods for some nested messages?

Here is an example: I don't see set_<...> methods for ANY of the
parameters in the db message.

What am I missing???

package pd;

message nv
{
repeated int32 Length = 1;
}

message dp
{
required int32 DesignID = 1;
repeated double Design = 2;
}

message Shape
{
required int32 size_m = 1;
required int32 size_n = 2;
}

message ds
{
required int32 DesignID = 1;
repeated double data = 2;
}

message db
{
required nv numVars = 1;
repeated dp despar = 2;
required Shape db_size = 3;
repeated ds dtst = 4;

Jason Hsueh

unread,
Jan 13, 2011, 8:42:29 PM1/13/11
to Linus, Protocol Buffers
On Thu, Jan 13, 2011 at 5:38 PM, Linus <suram...@gmail.com> wrote:
I am new to PB and I just ran into this. Is it possible that the PB
compiler does not generate set_<...> methods for some nested messages?

Here is an example: I don't see set_<...> methods for ANY of the
parameters in the db message.

For message type fields, there is no set_<...> method. The codegen produces mutable_<...> methods instead. Otherwise it is easy to write inefficient code - set would require a potentially expensive copy of the message.
 
--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.


Jason Hsueh

unread,
Jan 13, 2011, 8:44:57 PM1/13/11
to Linus, Protocol Buffers

Linus

unread,
Jan 13, 2011, 9:00:57 PM1/13/11
to Protocol Buffers
Cool!
Thank you for the clarification.

On Jan 13, 5:44 pm, Jason Hsueh <jas...@google.com> wrote:
> By the way this is documented here:http://code.google.com/apis/protocolbuffers/docs/reference/cpp-genera...
>
> On Thu, Jan 13, 2011 at 5:42 PM, Jason Hsueh <jas...@google.com> wrote:
>
> >> protobuf+u...@googlegroups.com<protobuf%2Bunsu...@googlegroups.com>
> >> .
Reply all
Reply to author
Forward
0 new messages