I think the right solution for putting an enum or primitive type in an Any field would be to use a wrapper type like you mentioned. Since there's no real way to create a generic wrapper for all enums, you would probably need to create a specific wrapper for each enum you want to store in an Any field. Does that work for your situation?
On Thu, Apr 13, 2017 at 7:31 PM, Josh Humphries <[email protected]> wrote: > I have a question about Any types in proto3. I'm guessing they aren't > quite fully-fleshed out since I haven't found a lot in the way of doc or > real support in the Java and Go implementations. > > My question: can you use enums or scalar types as values of an Any field? > If so, how do they look? > > For scalar types, I can understand if the answer is to use the wrapper > well-known types instead. *But* there doesn't appear to be a wrapper for > enum values. There is a well-known type named google.protobuf.EnumValue, > however it is part of the "schema description" well-known types and doesn't > carry enough data for wrapping an enum value (mainly, it's missing a > reference to its enum type, e.g. a type URL). > > It would be nice if the Any message's type_url field could be a URL that > returned an enum description, not just a message description. But the docs > state that the contents at that URL are an encoded google.protobuf.Type, > which describes a message and does not support enum types. Should it > instead have a single one-of field that can be an enum or message > description? > > Similarly, the type_url field for google.protobuf.Field is in a similar > conundrum. The doc states it is *"t**he field type URL, without the > scheme, for message or enumeration types"*, but nothing really talks > about enumeration types. The naive assumption is that the URL contents are > an enum description (e.g. an encoded google.protobuf.Enum). But if that's > the case, I could try to put an enum type into an Any field and indicate > that same URL. I then get into trouble because I'd be looking to parse a > google.protobuf.Type, in order to understand the Any message contents, > but actually get back the bytes for a google.protobuf.Enum. > > That doesn't seem sound. > > ---- > *Josh Humphries* > [email protected] > > -- > 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.
