Re: [protobuf] Enum values and proto3 Any types

2017-04-17 Thread Josh Humphries
That totally works. I don't actually need anything at the moment. But I was
looking at the spec and implementing some stuff around it -- like for
downloading and resolving type schemas from type URLs -- and noticed it as
an omission. The main omission is that nothing describes the contents of
google.protobuf.Field#type_url when the field's kind is enum. If it is an
encoded google.protobuf.Enum (which is the only thing that really makes
sense), it would be nice to state so in the spec. It might also be nice to
clearly call out in the doc for google.protobuf.Any that scalar types must
be boxed via wrappers (and enum types must be boxed via custom message
types).

FWIW, a generic wrapper type for an enum is certainly possible and would
look something like this:

message EnumValue {
  // The URL, optionally omitted scheme, for the enumeration type.
  type_url string
  valueint32
}

Unfortunately, EnumValue is a name conflict with the existing type that
describes an element in the enumeration. Maybe WrappedEnumValue?



*Josh Humphries*
jh...@bluegosling.com

On Mon, Apr 17, 2017 at 12:54 PM, Adam Cozzette 
wrote:

> 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 
> 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*
>> jh...@bluegosling.com
>>
>> --
>> 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 protobuf+unsubscr...@googlegroups.com.
>> To post to this group, send email to protobuf@googlegroups.com.
>> 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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


Re: [protobuf] Enum values and proto3 Any types

2017-04-17 Thread 'Adam Cozzette' via Protocol Buffers
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 
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*
> jh...@bluegosling.com
>
> --
> 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 protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> 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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


Re: [protobuf] Is possible to use enum from external class in .proto files?

2017-04-17 Thread Ronil Merchant
Thanks for the help, the suggested approach by henner worked. Was making an
error in the implementation

On Sat, Apr 15, 2017 at 2:57 AM, Adam Cozzette  wrote:

> Yes, that should work. Unless I'm misunderstanding something, you should
> just be able to do what Henner suggested above to accomplish this.
>
> On Fri, Apr 7, 2017 at 5:46 AM,  wrote:
>
>> Hi, on the same lines need help on an idea.
>>
>> Is it possible to define my enums in one .proto file and use them across
>> other .proto files.
>> In context of grpc protobuf3.
>>
>> Any help is appreciated.
>>
>> On Friday, December 7, 2012 at 10:49:29 AM UTC+5:30, Henner Zeller wrote:
>>>
>>> On 6 December 2012 15:32, Milan Stankovic  wrote:
>>>
 Is possible to use enum from external class ? I have couple .proto
 definition and all need to use same enum Type with same tokens. I want to
 avoid definition of same enum in every class and to avoid sync between, I
 have that enum in regular external c++ class which I use in code.
>>>
>>>
>>> It is not possible to have an external C++ enum somewhere, as this would
>>> require the proto parser to parse C++.
>>>
>>> However, what I usually do in that case is to define my enumeration in a
>>> separate *.proto file
>>> myenums.proto ---
>>> enum Foo {
>>>a = 1;
>>>b = 2;
>>>c = 3;
>>> };
>>>
>>> enum Bar {
>>> x = 1;
>>> }
>>> --
>>>
>>> from this, you can generate a myenums.pb.h - it essentially contains the
>>> enumerations as you would write them in C++ anyway, and some useful
>>> conversion functions (e.g. that convert it to a printable version).
>>> (also, this would generate enumeration for other languages as well, if
>>> you need it). From there, you can just use these enums as any other enums.
>>>
>>> Also, in your other proto-buffer files, you then can import this file
>>> and  use the enumeration
>>>
>>> otherprotofile.proto 
>>> import "myenmus.proto";
>>>
>>> message MyMessage {
>>>   Foo foo_enum = 1;
>>> };
>>> --
>>>
 --
 You received this message because you are subscribed to the Google
 Groups "Protocol Buffers" group.
 To view this discussion on the web visit https://groups.google.com/d/ms
 g/protobuf/-/H0dBbyOrwrgJ.
 To post to this group, send email to prot...@googlegroups.com.
 To unsubscribe from this group, send email to
 protobuf+u...@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 unsubscribe from this group and stop receiving emails from it, send an
>> email to protobuf+unsubscr...@googlegroups.com.
>> To post to this group, send email to protobuf@googlegroups.com.
>> 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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.