This is pretty much what the "ctype=STRING_PIECE" option does...  but it
wasn't included in the public release, since it required some extra classes
and we find we rarely use it internally.  I've been meaning to port it at
some point but haven't had time...  I'll bump it up my todo list.

On Fri, Mar 6, 2009 at 1:08 PM, Zachary Turner <>wrote:

> How hard would it be to modify the code generator so that whenever there
> was a field of type "bytes", a method was generated called
> assign_allocated(const char*, int nSize), that instead of creating an
> std::string(), would just store the raw pointer as well as the size, and not
> take ownership of the buffer?  Then when it was serializing, it would just
> do a memcpy(buf, size) into the serialized stream?  I guess if you then
> called mutable_fieldname()->assign() it would just NULL out the pointer and
> do what it normally does, and vice versa if you had previously called
> mutable_fieldname()->assign(), and then called this, it would remove the
> previous one and store your pointer.
> >

You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Reply via email to