You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Gianni Ambrosio <gi...@vi-grade.com> on 2019/08/05 08:01:47 UTC
map enum to strings
Dear All,
I have to share an enumerator, but also correspondent string value for
each enumerator value, between server and client. Client and server are
implemented in C++ and C#.
Here is my enum in a .thift file:
enum ViewerType {
ON_BOARD = 0,
MIRROR
}
I also need the client and server to map ON_BOARD enumerator to a
"ON_BOARD" string (and similarly for each enum value).
In C++ there is a trick to convert enums to string
(http://userpage.fu-berlin.de/~ram/pub/pub_jf47ht81Ht/c_preprocessor_applications_en)
but unfortunately I guess this method can not be used when the
enumerator is in a .thrift file.
So, is there anybody that already solved this case with thrift?
Cheers,
Gianni
Re: map enum to strings
Posted by Gianni Ambrosio <gi...@vi-grade.com>.
Hi,
I realized that in the thrift generated files there is a proper std::map:
extern const std::map<int, const char*> _ViewerType_VALUES_TO_NAMES;
That's exactly what I needed!
Gianni
On 05/08/2019 10:01, Gianni Ambrosio wrote:
> Dear All,
> I have to share an enumerator, but also correspondent string value for
> each enumerator value, between server and client. Client and server are
> implemented in C++ and C#.
>
> Here is my enum in a .thift file:
> enum ViewerType {
> ON_BOARD = 0,
> MIRROR
> }
>
> I also need the client and server to map ON_BOARD enumerator to a
> "ON_BOARD" string (and similarly for each enum value).
>
> In C++ there is a trick to convert enums to string
> (http://userpage.fu-berlin.de/~ram/pub/pub_jf47ht81Ht/c_preprocessor_applications_en)
> but unfortunately I guess this method can not be used when the
> enumerator is in a .thrift file.
>
> So, is there anybody that already solved this case with thrift?
>
> Cheers,
> Gianni