[protobuf] Question about set_allocated_foo/release_foo
I often have situations like this: void do_something(const std::string value) { my_proto_buffer.set_value(value); // serialize my_proto_buffer to a stream } Would it be valid to do this: void do_something(const std::string value) { my_proto_buffer.set_allocated_value(((std::string)value)); try { // serialize my_proto_buffer to a stream } catch (...) { my_proto_buffer.release_value() throw; } my_proto_buffer.release_value(); } or can I not rely on the internal string not being modified during serialization? Thanks, Kevin -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
[protobuf] Re: Question about set_allocated_foo/release_foo
Giving this a bump. This might also be considered a feature request (the ability to temporarily assign a string value to a protocol buffer during serialization, rather than copying it). --Kevin On Friday, March 8, 2013 1:49:29 PM UTC-8, Kevin Regan wrote: I often have situations like this: void do_something(const std::string value) { my_proto_buffer.set_value(value); // serialize my_proto_buffer to a stream } Would it be valid to do this: void do_something(const std::string value) { my_proto_buffer.set_allocated_value(((std::string)value)); try { // serialize my_proto_buffer to a stream } catch (...) { my_proto_buffer.release_value() throw; } my_proto_buffer.release_value(); } or can I not rely on the internal string not being modified during serialization? Thanks, Kevin -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: [protobuf] Re: Question about set_allocated_foo/release_foo
It is very common to have a const std::string argument. Indeed, just about any API that you would export to the end user would probably support taking aconst std::string key in this case. --Kevin On Thursday, March 14, 2013 6:31:54 PM UTC-7, Feng Xiao wrote: A better solution should be to refactor your code a little bit to pass in a mutable string object directly. You can expect protos to take movable objects in the future, but even when that happens you will still need to refactor your code. I don't think we will change protobuf to share references to const objects, nor will protobuf support shared_ptr stuff. On Thu, Mar 14, 2013 at 6:17 PM, Kevin Regan kevin@gmail.comjavascript: wrote: Giving this a bump. This might also be considered a feature request (the ability to temporarily assign a string value to a protocol buffer during serialization, rather than copying it). --Kevin On Friday, March 8, 2013 1:49:29 PM UTC-8, Kevin Regan wrote: I often have situations like this: void do_something(const std::string value) { my_proto_buffer.set_value(**value); // serialize my_proto_buffer to a stream } Would it be valid to do this: void do_something(const std::string value) { my_proto_buffer.set_allocated_**value(((std::string)value)); try { // serialize my_proto_buffer to a stream } catch (...) { my_proto_buffer.release_value(**) throw; } my_proto_buffer.release_value(**); } or can I not rely on the internal string not being modified during serialization? Thanks, Kevin -- 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+u...@googlegroups.com javascript:. To post to this group, send email to prot...@googlegroups.comjavascript: . Visit this group at http://groups.google.com/group/protobuf?hl=en. 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: [protobuf] Partial Decoding of message
This is how I handle the same issue. This would be similar to most multi-threaded daemons taking client input. The manager reads the message type and passes the socket/stream to a handling thread. On Monday, July 8, 2013 10:59:12 AM UTC-7, Ilia Mirkin wrote: Unfortunately it's not guaranteed that earlier fields appear earlier in the message. Although that is often the case, I wouldn't recommend writing your code s.t. it assumes this. The usual way that I handle this is by splitting the message into a header and data message, and then send something like header length varint header data data length varint data data That way your manager thread just decodes the header figures out what to do, and sends it on. Then the actual worker thread decodes the data. If this is not an option, you can write a custom decoder that just skips over fields you don't need to read. This is a little tricky, but if you're not trying to be too generic it shouldn't be that much code. On Mon, Jul 8, 2013 at 6:54 AM, itt...@gmail.com javascript: wrote: Hi Group, I am using protobuf in a multi-threaded software. Here manager thread decodes the protobuf encoded message and then assign the message to a particular worker thread based on key. I want to minimize per message processing at manager thread. Is it possible to encode the key at the head of message and decode only this key at manager thread. Complete decoding of message will be moved to the actual worker thread. thanks Ittium -- 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+u...@googlegroups.com javascript:. To post to this group, send email to prot...@googlegroups.comjavascript:. 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.
[protobuf] Simply library for converting between protobuf objects and JsonCpp objects.
I've been using the following code in my project to convert between JSON and protobuf objects (in C++): http://code.google.com/p/protobuf-to-jsoncpp/ http://code.google.com/p/protobuf-to-jsoncpp/source/browse/trunk/json_protobuf.h Currently, this has only a rudimentary Makefile (that I've run on Ubuntu 12.04) that expects the protobuf library and JsonCpp (http://jsoncpp.sourceforge.net/) to be installed in /usr/local. Please let me know what you think and if you have any suggestions. Thanks, Kevin Regan k.re...@emc.com kevin.d.re...@gmail.com -- 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.