Reputation: 5911
This question is similar to Is it possible to define an alias for type (enum or message) in google protobuf?
But I want to know if thrift supports similar function. I couldnt find any such in documentation.
I want to write something like the following in thrift
enum EnumAllowingAlias {
option allow_alias = true;
UNKNOWN = 0;
STARTED = 1;
RUNNING = 1;
}
Upvotes: 0
Views: 532
Reputation: 1172
Thrift does indeed support typedefs. IMHO the Thrift IDL is one of the most elegant out there. Here's a couple typedef examples:
ubuntu@Kassarat:~$ cat test.thrift
struct ICRFPosition {
1: double right_ascension
2: double declination
3: optional i16 ecliptic_year
}
typedef ICRFPosition ICRFP
enum RadioObservationSystem {
Parkes = 1
Arecibo = 2
GMRT = 17
LOFAR = 18
Socorro = 25
VLBA = 51
}
typedef RadioObservationSystem ROS
ubuntu@Kassarat:~$ docker run -v ~:/data apache/thrift -o /data --gen cpp /data/test.thrift
ubuntu@Kassarat:~$ grep "ICRFP;" gen-cpp/*
gen-cpp/test_types.h:typedef class ICRFPosition ICRFP;
ubuntu@Kassarat:~$ grep "ROS;" gen-cpp/*
gen-cpp/test_types.h:typedef RadioObservationSystem::type ROS;
ubuntu@Kassarat:~$
Upvotes: 0