[protobuf] C++ Generated code Warnings fix ? has uninitialized variables, for mutable type which will have pointer so accessing uninitialized pointer is risky.
Hi, C++ Generated code has warning like uninitialized variables, for mutable type which will have pointer so accessing uninitialized pointer is risky. Any solution to fix all pointer type initialized to nullptr? Regards, Raghavendra -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/37e64dba-477f-4cef-9da6-0b17486f1dbfo%40googlegroups.com.
[protobuf] Mutable pointer not consistent with official doc.
Hi all, As said in the official document [C++ Generated Code https://developers.google.com/protocol-buffers/docs/reference/cpp-generated::Singular String Fields]: https://lh4.googleusercontent.com/-oYL7QapLFwA/VI_h8UnnW1I/AFs/EKBP3yHOz0s/s1600/0.png But in my test, the string pointed by the returned pointer just has the default value. My test environment is Win764bit, Visual Studio 2013. Here is my test: *Message definition:* https://lh6.googleusercontent.com/-r19642fX7_A/VI_ihF6yEhI/AF0/WgbNZeFnGEc/s1600/1.png *Test code:(without set the string field before use its mutable pointer)* https://lh5.googleusercontent.com/-w1aWpS9uEw4/VI_iuJuVDTI/AF8/XXMNOCrftE0/s1600/2.png *Result:* https://lh4.googleusercontent.com/-3JmIUw0XnFo/VI_jWmIiC1I/AGM/e7E6bKyC4NA/s1600/3.png Why? Please notice me if I misunderstood the doc. -- 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/d/optout.
Re: [protobuf] Mutable pointer not consistent with official doc.
I think this is a bug in the implementation. Filed issue: https://github.com/google/protobuf/issues/141 On Mon, Dec 15, 2014 at 11:47 PM, John Sun ih4...@gmail.com wrote: Hi all, As said in the official document [C++ Generated Code https://developers.google.com/protocol-buffers/docs/reference/cpp-generated::Singular String Fields]: https://lh4.googleusercontent.com/-oYL7QapLFwA/VI_h8UnnW1I/AFs/EKBP3yHOz0s/s1600/0.png But in my test, the string pointed by the returned pointer just has the default value. My test environment is Win764bit, Visual Studio 2013. Here is my test: *Message definition:* https://lh6.googleusercontent.com/-r19642fX7_A/VI_ihF6yEhI/AF0/WgbNZeFnGEc/s1600/1.png *Test code:(without set the string field before use its mutable pointer)* https://lh5.googleusercontent.com/-w1aWpS9uEw4/VI_iuJuVDTI/AF8/XXMNOCrftE0/s1600/2.png *Result:* https://lh4.googleusercontent.com/-3JmIUw0XnFo/VI_jWmIiC1I/AGM/e7E6bKyC4NA/s1600/3.png Why? Please notice me if I misunderstood the doc. -- 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/d/optout. -- 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/d/optout.
mutable
I am having trouble accessing many members of my .proto file. It seems that compound members are not accessible with set_() method calls. I saw in your example code the use of mutable_() calls. What does this apply to and is there documentation on it? could this be the solution to my problem? Thanks! Jay --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---
Re: mutable
Hi, On Wed, Sep 23, 2009 at 08:13, jayt0...@gmail.com jayt0...@gmail.com wrote: I am having trouble accessing many members of my .proto file. It seems that compound members are not accessible with set_() method calls. I saw in your example code the use of mutable_() calls. What does this apply to and is there documentation on it? could this be the solution to my problem? You should describe your problem more closely, it is not quite clear what you mean. If you have a message Bar, that contains a message Foo, say: message Foo { optional int32 value = 1; } message Bar { optional Foo foo = 1; } you would access 'foo' to set a value with Bar message; message.mutable_foo()-set_value(42); If there is no 'foo', it will implicitly be created (so has_bar() will return 'true' afterwards'). .. while accessing can be const if (message.has_foo()) printf(%d, message.bar().value()); But it sounds like you would like to 'set' a complete Foo message. So if you want to 'set' a complete Foo, you would use CopyFrom() Foo foo_message; foo_message.set_value(42); Bar bar_message; bar_message.mutable_bar()-CopyFrom(foo_message); -h --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---
Re: mutable
Bar bar_message; bar_message.mutable_bar()-CopyFrom(foo_message); .. and that should of course be a bar_message.mutable_foo()-CopyFrom(foo_message); -h --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---
Re: mutable
wow. I will try that. Yes, I am trying to set a complete 'foo' message. Is there documentation anywhere on this? I am coming up empty with web searches... On Sep 23, 8:25 am, Henner Zeller h.zel...@acm.org wrote: Hi, On Wed, Sep 23, 2009 at 08:13, jayt0...@gmail.com jayt0...@gmail.com wrote: I am having trouble accessing many members of my .proto file. It seems that compound members are not accessible with set_() method calls. I saw in your example code the use of mutable_() calls. What does this apply to and is there documentation on it? could this be the solution to my problem? You should describe your problem more closely, it is not quite clear what you mean. If you have a message Bar, that contains a message Foo, say: message Foo { optional int32 value = 1; } message Bar { optional Foo foo = 1; } you would access 'foo' to set a value with Bar message; message.mutable_foo()-set_value(42); If there is no 'foo', it will implicitly be created (so has_bar() will return 'true' afterwards'). .. while accessing can be const if (message.has_foo()) printf(%d, message.bar().value()); But it sounds like you would like to 'set' a complete Foo message. So if you want to 'set' a complete Foo, you would use CopyFrom() Foo foo_message; foo_message.set_value(42); Bar bar_message; bar_message.mutable_bar()-CopyFrom(foo_message); -h --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---
Re: mutable
message foo1 { optional int32 value1 = 1; optional int32 value2 = 2; } message foo2 { optional foo1 stuff1 = 1; optional foo2 stuff2 = 2; } foo1 msg_foo1; foo2 msg_foo2; msg_foo2.set_stuff1(foo1); This is the concept of what I'm trying to do. On Sep 23, 8:25 am, Henner Zeller h.zel...@acm.org wrote: Hi, On Wed, Sep 23, 2009 at 08:13, jayt0...@gmail.com jayt0...@gmail.com wrote: I am having trouble accessing many members of my .proto file. It seems that compound members are not accessible with set_() method calls. I saw in your example code the use of mutable_() calls. What does this apply to and is there documentation on it? could this be the solution to my problem? You should describe your problem more closely, it is not quite clear what you mean. If you have a message Bar, that contains a message Foo, say: message Foo { optional int32 value = 1; } message Bar { optional Foo foo = 1; } you would access 'foo' to set a value with Bar message; message.mutable_foo()-set_value(42); If there is no 'foo', it will implicitly be created (so has_bar() will return 'true' afterwards'). .. while accessing can be const if (message.has_foo()) printf(%d, message.bar().value()); But it sounds like you would like to 'set' a complete Foo message. So if you want to 'set' a complete Foo, you would use CopyFrom() Foo foo_message; foo_message.set_value(42); Bar bar_message; bar_message.mutable_bar()-CopyFrom(foo_message); -h --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---
Re: mutable
On Wed, Sep 23, 2009 at 08:37, jayt0...@gmail.com jayt0...@gmail.com wrote: wow. I will try that. Yes, I am trying to set a complete 'foo' message. Is there documentation anywhere on this? I am coming up empty with web searches... The api-documentation has it http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google.protobuf.message.html .. and the tutorial mentions them as well, but not with an example http://code.google.com/apis/protocolbuffers/docs/cpptutorial.html On Sep 23, 8:25 am, Henner Zeller h.zel...@acm.org wrote: Hi, On Wed, Sep 23, 2009 at 08:13, jayt0...@gmail.com jayt0...@gmail.com wrote: I am having trouble accessing many members of my .proto file. It seems that compound members are not accessible with set_() method calls. I saw in your example code the use of mutable_() calls. What does this apply to and is there documentation on it? could this be the solution to my problem? You should describe your problem more closely, it is not quite clear what you mean. If you have a message Bar, that contains a message Foo, say: message Foo { optional int32 value = 1; } message Bar { optional Foo foo = 1; } you would access 'foo' to set a value with Bar message; message.mutable_foo()-set_value(42); If there is no 'foo', it will implicitly be created (so has_bar() will return 'true' afterwards'). .. while accessing can be const if (message.has_foo()) printf(%d, message.bar().value()); But it sounds like you would like to 'set' a complete Foo message. So if you want to 'set' a complete Foo, you would use CopyFrom() Foo foo_message; foo_message.set_value(42); Bar bar_message; bar_message.mutable_bar()-CopyFrom(foo_message); -h --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---
Re: mutable
On Wed, Sep 23, 2009 at 08:45, jayt0...@gmail.com jayt0...@gmail.com wrote: message foo1 { optional int32 value1 = 1; optional int32 value2 = 2; } message foo2 { optional foo1 stuff1 = 1; optional foo2 stuff2 = 2; } foo1 msg_foo1; foo2 msg_foo2; msg_foo2.set_stuff1(foo1); This is the concept of what I'm trying to do. Yeah, that will work with CopyFrom() msg_foo2.mutable_stuff1()-CopyFrom(foo1); On Sep 23, 8:25 am, Henner Zeller h.zel...@acm.org wrote: Hi, On Wed, Sep 23, 2009 at 08:13, jayt0...@gmail.com jayt0...@gmail.com wrote: I am having trouble accessing many members of my .proto file. It seems that compound members are not accessible with set_() method calls. I saw in your example code the use of mutable_() calls. What does this apply to and is there documentation on it? could this be the solution to my problem? You should describe your problem more closely, it is not quite clear what you mean. If you have a message Bar, that contains a message Foo, say: message Foo { optional int32 value = 1; } message Bar { optional Foo foo = 1; } you would access 'foo' to set a value with Bar message; message.mutable_foo()-set_value(42); If there is no 'foo', it will implicitly be created (so has_bar() will return 'true' afterwards'). .. while accessing can be const if (message.has_foo()) printf(%d, message.bar().value()); But it sounds like you would like to 'set' a complete Foo message. So if you want to 'set' a complete Foo, you would use CopyFrom() Foo foo_message; foo_message.set_value(42); Bar bar_message; bar_message.mutable_bar()-CopyFrom(foo_message); -h --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---
Re: mutable
so this has to be done whenever there is a compound type? I.e. types used for messages that are defined in other messages? If not, what is the rule for when a mutable pointer has to be obtained? I am also noticing that I am having what appears to be this same problem when using 'string' type for foo1. Trying to find a pattern here... Thanks so much for your help. You are a life saver... Jay On Sep 23, 8:47 am, Henner Zeller h.zel...@acm.org wrote: On Wed, Sep 23, 2009 at 08:45, jayt0...@gmail.com jayt0...@gmail.com wrote: message foo1 { optional int32 value1 = 1; optional int32 value2 = 2; } message foo2 { optional foo1 stuff1 = 1; optional foo2 stuff2 = 2; } foo1 msg_foo1; foo2 msg_foo2; msg_foo2.set_stuff1(foo1); This is the concept of what I'm trying to do. Yeah, that will work with CopyFrom() msg_foo2.mutable_stuff1()-CopyFrom(foo1); On Sep 23, 8:25 am, Henner Zeller h.zel...@acm.org wrote: Hi, On Wed, Sep 23, 2009 at 08:13, jayt0...@gmail.com jayt0...@gmail.com wrote: I am having trouble accessing many members of my .proto file. It seems that compound members are not accessible with set_() method calls. I saw in your example code the use of mutable_() calls. What does this apply to and is there documentation on it? could this be the solution to my problem? You should describe your problem more closely, it is not quite clear what you mean. If you have a message Bar, that contains a message Foo, say: message Foo { optional int32 value = 1; } message Bar { optional Foo foo = 1; } you would access 'foo' to set a value with Bar message; message.mutable_foo()-set_value(42); If there is no 'foo', it will implicitly be created (so has_bar() will return 'true' afterwards'). .. while accessing can be const if (message.has_foo()) printf(%d, message.bar().value()); But it sounds like you would like to 'set' a complete Foo message. So if you want to 'set' a complete Foo, you would use CopyFrom() Foo foo_message; foo_message.set_value(42); Bar bar_message; bar_message.mutable_bar()-CopyFrom(foo_message); -h --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---
Re: mutable
On Wed, Sep 23, 2009 at 08:54, jayt0...@gmail.com jayt0...@gmail.com wrote: so this has to be done whenever there is a compound type? I.e. types used for messages that are defined in other messages? If not, what is the rule for when a mutable pointer has to be obtained? I am also noticing that I am having what appears to be this same problem when using 'string' type for foo1. So a string you can just set like that message Foo { optional string value = 1; } Foo message; message.set_value(hello world); Trying to find a pattern here... Thanks so much for your help. You are a life saver... Jay On Sep 23, 8:47 am, Henner Zeller h.zel...@acm.org wrote: On Wed, Sep 23, 2009 at 08:45, jayt0...@gmail.com jayt0...@gmail.com wrote: message foo1 { optional int32 value1 = 1; optional int32 value2 = 2; } message foo2 { optional foo1 stuff1 = 1; optional foo2 stuff2 = 2; } foo1 msg_foo1; foo2 msg_foo2; msg_foo2.set_stuff1(foo1); This is the concept of what I'm trying to do. Yeah, that will work with CopyFrom() msg_foo2.mutable_stuff1()-CopyFrom(foo1); On Sep 23, 8:25 am, Henner Zeller h.zel...@acm.org wrote: Hi, On Wed, Sep 23, 2009 at 08:13, jayt0...@gmail.com jayt0...@gmail.com wrote: I am having trouble accessing many members of my .proto file. It seems that compound members are not accessible with set_() method calls. I saw in your example code the use of mutable_() calls. What does this apply to and is there documentation on it? could this be the solution to my problem? You should describe your problem more closely, it is not quite clear what you mean. If you have a message Bar, that contains a message Foo, say: message Foo { optional int32 value = 1; } message Bar { optional Foo foo = 1; } you would access 'foo' to set a value with Bar message; message.mutable_foo()-set_value(42); If there is no 'foo', it will implicitly be created (so has_bar() will return 'true' afterwards'). .. while accessing can be const if (message.has_foo()) printf(%d, message.bar().value()); But it sounds like you would like to 'set' a complete Foo message. So if you want to 'set' a complete Foo, you would use CopyFrom() Foo foo_message; foo_message.set_value(42); Bar bar_message; bar_message.mutable_bar()-CopyFrom(foo_message); -h --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---
Re: mutable
so this has to be done whenever there is a compound type? I.e. types used for messages that are defined in other messages? If not, what is the rule for when a mutable pointer has to be obtained? I am also noticing that I am having what appears to be this same problem when using 'string' type for foo1. Trying to find a pattern here... Thanks so much for your help. You are a life saver... Jay On Sep 23, 8:47 am, Henner Zeller h.zel...@acm.org wrote: On Wed, Sep 23, 2009 at 08:45, jayt0...@gmail.com jayt0...@gmail.com wrote: message foo1 { optional int32 value1 = 1; optional int32 value2 = 2; } message foo2 { optional foo1 stuff1 = 1; optional foo2 stuff2 = 2; } foo1 msg_foo1; foo2 msg_foo2; msg_foo2.set_stuff1(foo1); This is the concept of what I'm trying to do. Yeah, that will work with CopyFrom() msg_foo2.mutable_stuff1()-CopyFrom(foo1); On Sep 23, 8:25 am, Henner Zeller h.zel...@acm.org wrote: Hi, On Wed, Sep 23, 2009 at 08:13, jayt0...@gmail.com jayt0...@gmail.com wrote: I am having trouble accessing many members of my .proto file. It seems that compound members are not accessible with set_() method calls. I saw in your example code the use of mutable_() calls. What does this apply to and is there documentation on it? could this be the solution to my problem? You should describe your problem more closely, it is not quite clear what you mean. If you have a message Bar, that contains a message Foo, say: message Foo { optional int32 value = 1; } message Bar { optional Foo foo = 1; } you would access 'foo' to set a value with Bar message; message.mutable_foo()-set_value(42); If there is no 'foo', it will implicitly be created (so has_bar() will return 'true' afterwards'). .. while accessing can be const if (message.has_foo()) printf(%d, message.bar().value()); But it sounds like you would like to 'set' a complete Foo message. So if you want to 'set' a complete Foo, you would use CopyFrom() Foo foo_message; foo_message.set_value(42); Bar bar_message; bar_message.mutable_bar()-CopyFrom(foo_message); -h --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---
Re: mutable
so this has to be done whenever there is a compound type? I.e. types used for messages that are defined in other messages? If not, what is the rule for when a mutable pointer has to be obtained? I am also noticing that I am having what appears to be this same problem when using 'string' type for foo1. Trying to find a pattern here... Thanks so much for your help. You are a life saver... Jay On Sep 23, 8:47 am, Henner Zeller h.zel...@acm.org wrote: On Wed, Sep 23, 2009 at 08:45, jayt0...@gmail.com jayt0...@gmail.com wrote: message foo1 { optional int32 value1 = 1; optional int32 value2 = 2; } message foo2 { optional foo1 stuff1 = 1; optional foo2 stuff2 = 2; } foo1 msg_foo1; foo2 msg_foo2; msg_foo2.set_stuff1(foo1); This is the concept of what I'm trying to do. Yeah, that will work with CopyFrom() msg_foo2.mutable_stuff1()-CopyFrom(foo1); On Sep 23, 8:25 am, Henner Zeller h.zel...@acm.org wrote: Hi, On Wed, Sep 23, 2009 at 08:13, jayt0...@gmail.com jayt0...@gmail.com wrote: I am having trouble accessing many members of my .proto file. It seems that compound members are not accessible with set_() method calls. I saw in your example code the use of mutable_() calls. What does this apply to and is there documentation on it? could this be the solution to my problem? You should describe your problem more closely, it is not quite clear what you mean. If you have a message Bar, that contains a message Foo, say: message Foo { optional int32 value = 1; } message Bar { optional Foo foo = 1; } you would access 'foo' to set a value with Bar message; message.mutable_foo()-set_value(42); If there is no 'foo', it will implicitly be created (so has_bar() will return 'true' afterwards'). .. while accessing can be const if (message.has_foo()) printf(%d, message.bar().value()); But it sounds like you would like to 'set' a complete Foo message. So if you want to 'set' a complete Foo, you would use CopyFrom() Foo foo_message; foo_message.set_value(42); Bar bar_message; bar_message.mutable_bar()-CopyFrom(foo_message); -h --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---
Re: mutable
what about if you have something like message foo1 { optional int32 value1 = 1; optional int32 value2 = 2; } message foo2 { repeated foo1 stuff1 = 1; optional foo1 stuff2 = 2; } do you know how to add another stuff1 to foo2 structure? On Sep 23, 8:45 am, jayt0...@gmail.com jayt0...@gmail.com wrote: message foo1 { optional int32 value1 = 1; optional int32 value2 = 2; } message foo2 { optional foo1 stuff1 = 1; optional foo2 stuff2 = 2; } foo1 msg_foo1; foo2 msg_foo2; msg_foo2.set_stuff1(foo1); This is the concept of what I'm trying to do. On Sep 23, 8:25 am, Henner Zeller h.zel...@acm.org wrote: Hi, On Wed, Sep 23, 2009 at 08:13, jayt0...@gmail.com jayt0...@gmail.com wrote: I am having trouble accessing many members of my .proto file. It seems that compound members are not accessible with set_() method calls. I saw in your example code the use of mutable_() calls. What does this apply to and is there documentation on it? could this be the solution to my problem? You should describe your problem more closely, it is not quite clear what you mean. If you have a message Bar, that contains a message Foo, say: message Foo { optional int32 value = 1; } message Bar { optional Foo foo = 1; } you would access 'foo' to set a value with Bar message; message.mutable_foo()-set_value(42); If there is no 'foo', it will implicitly be created (so has_bar() will return 'true' afterwards'). .. while accessing can be const if (message.has_foo()) printf(%d, message.bar().value()); But it sounds like you would like to 'set' a complete Foo message. So if you want to 'set' a complete Foo, you would use CopyFrom() Foo foo_message; foo_message.set_value(42); Bar bar_message; bar_message.mutable_bar()-CopyFrom(foo_message); -h --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---
Re: mutable
On Wed, Sep 23, 2009 at 09:53, jayt0...@gmail.com jayt0...@gmail.com wrote: what about if you have something like message foo1 { optional int32 value1 = 1; optional int32 value2 = 2; } message foo2 { repeated foo1 stuff1 = 1; optional foo1 stuff2 = 2; } do you know how to add another stuff1 to foo2 structure? foo1* added_value = foo2_message.add_stuff1(); added_value-set_value1(42); added_value-set_value2(43); .. or the usual with CopyFrom() foo2_message.add_stuff1()-CopyFrom(some_foo1); On Sep 23, 8:45 am, jayt0...@gmail.com jayt0...@gmail.com wrote: message foo1 { optional int32 value1 = 1; optional int32 value2 = 2; } message foo2 { optional foo1 stuff1 = 1; optional foo2 stuff2 = 2; } foo1 msg_foo1; foo2 msg_foo2; msg_foo2.set_stuff1(foo1); This is the concept of what I'm trying to do. On Sep 23, 8:25 am, Henner Zeller h.zel...@acm.org wrote: Hi, On Wed, Sep 23, 2009 at 08:13, jayt0...@gmail.com jayt0...@gmail.com wrote: I am having trouble accessing many members of my .proto file. It seems that compound members are not accessible with set_() method calls. I saw in your example code the use of mutable_() calls. What does this apply to and is there documentation on it? could this be the solution to my problem? You should describe your problem more closely, it is not quite clear what you mean. If you have a message Bar, that contains a message Foo, say: message Foo { optional int32 value = 1; } message Bar { optional Foo foo = 1; } you would access 'foo' to set a value with Bar message; message.mutable_foo()-set_value(42); If there is no 'foo', it will implicitly be created (so has_bar() will return 'true' afterwards'). .. while accessing can be const if (message.has_foo()) printf(%d, message.bar().value()); But it sounds like you would like to 'set' a complete Foo message. So if you want to 'set' a complete Foo, you would use CopyFrom() Foo foo_message; foo_message.set_value(42); Bar bar_message; bar_message.mutable_bar()-CopyFrom(foo_message); -h --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---
Re: mutable
The different accessor functions for C++ protobuf classes are documented in detail here: http://code.google.com/apis/protocolbuffers/docs/reference/cpp-generated.html Message objects can be large, so you should avoid copying them if possible. Instead, you should use the mutable_() accessor to get a pointer to the sub-message early on, and then modify that sub-message directly, rather than build a separate object and then copy it. For example: DON'T do this: Foo foo; SetupFoo(foo); Bar bar; bar.mutable_foo()-CopyFrom(foo); Do this instead: Bar bar; SetupFoo(bar.mutable_foo()); This avoids copying, thus making your code more efficient. It's also shorter. On Wed, Sep 23, 2009 at 8:13 AM, jayt0...@gmail.com jayt0...@gmail.comwrote: I am having trouble accessing many members of my .proto file. It seems that compound members are not accessible with set_() method calls. I saw in your example code the use of mutable_() calls. What does this apply to and is there documentation on it? could this be the solution to my problem? Thanks! Jay --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---