On Thu, Jan 7, 2010 at 12:42 PM, Nigel Pickard <pickard.ni...@gmail.com>wrote:

> I read various messages on this subject in the message board, but
> couldn't really find what I was looking for.  Here is what I'd like to
> do:
>
> 1. I have messages of type Animal, Vegetable and Mineral.
> 2. I want to send these 3 dissimilar objects of Animal, Vegetable and
> Mineral to a file or output stream using the writeDelimitedTo method
> so I have an automatic delimiter.  I do not know which order these
> objects will be in.
>
> Since I don't know up front which type is coming first, from the
> techniques section (http://code.google.com/apis/protocolbuffers/docs/
> techniques.html) I see I can use a wrapper message, and then
> interrogate the wrapper message to determine the type.
>
> However, if we get many different potential types of messages, this
> approach could get messy very quickly both from maintaining the proto
> file (even with extensions) and interrogating the wrapper (e.g.
> testing if the wrapper contains a certain type) .  Are there any other
> options I could use?  Advantages/disadvantages?
>

Use the wrapper message technique combined with extensions:

  message Wrapper {
    extensions 100 to max;
  }

  // Can be in a different file.
  extend Wrapper {
    optional Animal animal_ext = 100;
    optional Vegetable vegetalbe_ext = 101;
    optional Mineral mineral_ext = 102;
  }


>
> One thought was to send a separate message object containing the type
> information (could be as simple as a string such as a class name etc)
> preceding each message, but I'm not sure that would work and it could
> be very expensive.  Has anyone else used anything different from the
> way outlined in the techniques section?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To post to this group, send email to proto...@googlegroups.com.
> To unsubscribe from this group, send email to
> protobuf+unsubscr...@googlegroups.com<protobuf%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/protobuf?hl=en.
>
>
>
>
--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to proto...@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.

Reply via email to