Perhaps I'm dense, but what's the problem? That gdb doesn't print the
exact type info that you expected? That could well be the difference
between -O2 and -O0...

On Mon, Aug 19, 2013 at 9:55 AM, Alvaro Aguilera
<alvaro.aguil...@gmail.com> wrote:
> Hello,
>
> I'm having a strange problem when setting an string value in a protocol
> buffer. Keep in mind that my experience in C++ and PB is rather limited.
> The .proto file looks more or less like this:
>
> ----------------------
> package buffers;
>
> message AttributeValue {
>
>     enum Type {
>         INT64   = 0;
>         UINT64  = 1;
>         INT32   = 2;
>         UINT32  = 3;
>         FLOAT   = 4;
>         DOUBLE  = 5;
>         INVALID = 6;
>         STRING  = 7;
>     }
>
>     required   Type type = 1;
>     optional   int32 i32 = 2;
>     optional   int64 i64 = 3;
>     optional uint32 ui32 = 4;
>     optional uint64 ui64 = 5;
>     optional     float f = 6;
>     optional    double d = 7;
>     optional  string str = 8;
>
> }
>
> ----------------------
>
> I also have a function to convert a class "VariableDatatype" into an
> AttributeValue buffer. It looks like this:
>
> void BufferConverter::attribute_value(const VariableDatatype &s_atv,
> buffers::AttributeValue &b_atv)
> {
>     switch(s_atv.type()) {
>     case VariableDatatype::Type::STRING:
>         b_atv.set_type(buffers::AttributeValue::STRING);
>         b_atv.set_str(s_atv.str());
>         break;
>     }
> }
>
>
> In the main function I try to create a protocol buffer containing the string
> stored in VariableDatatype by using the attribute_value() function in the
> way shown below:
>
> main-1()
> {
>     buffers::AttributeValue *bs = new buffers::AttributeValue();
>     c.attribute_value(ds, *bs);
>
> }
>
> This doesn't work.
> If I print the value of b_atv inside the attribute_value function using gdb
> I get something like:
>
> gdb print b_atv
> 26 = (buffers::AttributeValue &) @0x6496b0: {<google::protobuf::Message> =
> {<google::protobuf::MessageLite> = {
>
>
> However, when I print *bs from inside main-1, I get something different:
>
> gdb print *bs
> $36 = {<google::protobuf::Message> = {<google::protobuf::MessageLite> =
> {_vptr.MessageLite = 0x642650 <vtable for buffers::AttributeValue+16>
>
> I can work around the problem by using the following main-2:
>
> main-2()
> {
>     buffers::AttributeValue *bs = new buffers::AttributeValue();
>     buffers::AttributeValue &bss = *bs;
>
>     c.attribute_value(ds, bss);
> }
>
> but that's not very elegant. Can someone point me to the right way to handle
> this?
>
> Thank you
> A.
>
>
>
>
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at http://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to