Hi Kenton,

Sorry the parameter classes are legacy code and persisted to the DB as
well. So I have to figure out what's the best approach defining my
proto classes.

What I see is that there is the way of using extensions in the proto
files. As far as I understand it is an extension of members (an not
classes) in another proto file. Correct?

So in my case the files in OStringParameterMessage.proto and
OLongParameterMessage.proto extends OParameterMessage.proto with a
member "value" of type string and int64.

The OListParameterMessage.proto then extends it with a member value of
type List (containing OParameterMessage.OParameter instances).

In the OListParameter.writeObject() I build OParameter messages. But
wouldn't there be a problem since the value is either of type String
or Quantity (depending on the subclass of OParameter)? Probably I have
to define different member names.

Tai


On 5 Aug., 03:05, Kenton Varda <ken...@google.com> wrote:
> Can you just have the OParameter message contain optional fields of type
> string and int64, where only one of the two is ever set?  Then don't have
> specific types corresponding to OStringParameter and OLongParameter.
>
> On Tue, Aug 4, 2009 at 5:07 PM, Tai <maitai.tru...@gmail.com> wrote:
>
> > Hi,
>
> > I have an (abstract) class:
> > - OParameter with a member String key
>
> > Now there are also two subclasses of OParameter:
> > - OStringParameter with a member String value
> > - OLongParameter with a member long value
>
> > By using Protocol Buffers I define the proto files:
> > - OParameterMessage.proto
> > - OStringParameterMessage.proto
> > - OLongParameterMessage.proto
>
> > The files are independent from each other (no extension is used). As
> > far as I understand this is how Protocol Buffers should be used. All
> > classes (OParameter, OStringParameter and OLongParameter) then
> > implements the writeObject() and readObject() and each class just uses
> > their Protocol message and sets their members. Like:
> > - Class OStringParameter.writeObject() builds a message and sets only
> > its member (value)
> > - The superclass OParameter.writeObject() builds a message and sets
> > only its member (key)
>
> > The same goes for the readObject().
>
> > Okay. So far so good. But now I have a class called OListParameter and
> > its member (value) is a list of OParameter containing instances of
> > both types: OStringParameter and OLongParameter.
>
> > How do I describe this in a proto file?
>
> > Thanks Tai
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to