Is there thrift support for alias

339 views Asked by At

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;
}
1

There are 1 answers

3
codeSF On

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:~$