You need to get a EnumDescriptor for the field in question, and then
retrieve the EnumValueDescriptor using FindValueByNumber. That will
have all the name information you need. To get the EnumDescriptor of
an enum Foo, you can use Foo_descriptor() which should be in the
generated code. I assume this is similar to what NameOfEnum does
(should be easy to check, of course, just look at the code).

On Mon, Oct 7, 2013 at 10:31 AM, amirk <kleen.a...@gmail.com> wrote:
> Hi,
>
> I am new to protobuf, Can someone please post an example of enum to string
> conversion in C++?
> I see that there is generated code for it (see below example for enum called
> XXX), but when I try to call I get a segmentation fault.
>
> Thanks,
> Amir
>
> inline const ::std::xxx& XXX_XXXIdentifier_Name(XXX_XXXIdentifier value) {
>   return ::google::protobuf::internal::NameOfEnum(
>     XXX_XXXIdentifier_descriptor(), value);
> }
> inline bool XXX_XXXIdentifier_Parse(
>     const ::std::xxx& name, XXX_XXXIdentifier* value) {
>   return ::google::protobuf::internal::ParseNamedEnum<XXX_XXXIdentifier>(
>     XXX_XXXIdentifier_descriptor(), name, value);
> }
>
> --
> 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 http://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
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 http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to