Thanks Adam!

I'll look into arena allocation, since all I really want is
destroy-after-use. Will that do it?

Regarding "polymorphism", what I'm really after is some way to manage and
act upon a group of messages, something like:
1. Get incoming packet from a queue, deserialize it and create the message
object.
2. Send the message object (hence the need for a base class) to a
"dispatcher"
3. Dispatcher invokes the appropriate processing method which creates a
response message.
4. Serialize the response and send packet on return queue.

Steps 1 and 3 are the parts that I'm grappling with, both in Java and C++.
Any tips on
-- The best way to examine the packet and create the correct message?  I
have some freedom to put framing around the packet if necessary.
-- The best way to create and invoke a message->method mapping in Java /
C++?

Thanks
john


On Fri, Jun 29, 2018 at 4:13 PM Adam Cozzette <[email protected]> wrote:

> I've found that std::unique_ptr usually works well with messages in C++.
> Probably the only case where things get a little bit complicated is if
> you're using arena allocation
> <https://developers.google.com/protocol-buffers/docs/reference/arenas>,
> since in that case the arena owns the message and you must not call delete
> on it. Within Google we have a special pointer type that keeps track of
> whether a message was arena-allocated or not, and makes sure to call delete
> only if the message was heap-allocated.
>
> About inheritance, there is no way to make all messages inherit from a
> specified class. However, all messages do inherit from
> google::protobuf::MessageLite (and google::protobuf::Message if you're not
> using the lite runtime), so that can be useful if you want to write code
> that operates on arbitrary message types.
>
> On Thu, Jun 28, 2018 at 12:31 PM John Lilley <[email protected]> wrote:
>
>> I have two (maybe unrelated) questions:
>> -- Is there a recommended way to wrap "smart pointers" around protobuf
>> message objects in C++?
>> -- Is there a way to make all messages inherit from the same base class
>> or interface?  Note I am not trying to make message definitions inherit
>> from each other; I only want the classes generated C++ code to inherit from
>> a class that I control.'
>> Thanks
>> john
>>
>> --
>> 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 [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at https://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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to