More on a C based thrift interface.

I've completed the first phases of the c-thrift translator. You can see a little example lower in the e-mail.

My question is this: would the incubator the appropriate venue to host the tool, or would you recommend I look elsewhere such as sourceforge?

I understand that this is _NOT_ the main line of work for the thrift project, which centers around taking Thrift IDL descriptions and turning them into abstracted where one can specify both different protocols and different transports at run-time.

Instead, c-thrift chooses to:
- start from annotated C
- focus on efficiency
- generate code where the protocol and transport are bound in at translation time.

Its a completely different approach, with a different philosophy, so I'm quite comfortable with people telling me that this is NOT the correct place to put such a tool; however, I thought I'd give the team right-of-first-refusal.

Thanks

--------------

A little more detail about the tool: it (currently) takes an annotated C file and generates client code that interfaces with servers via an O_NONBLOCK socket. [Obviously, its not complete].

The annotations support generation of functions/structures that
- use or don't use seqid as a parameter
- use or don't use isset
- transmit/recieve NULL terminated C-strings to T_STRING
- pass T_LIST & T_SET types as C arrays with a length parameter
- support pre-allocated receives and allocate-on-recieve.

For instance, the tutorial example could be written:

/* @thrift: begin */
struct Work {
  int           num1;   /* @thrift: 1 */
  int           num2;
  enum Operation op;
  char *        comment;        /* @thrift: optional */
};

struct InvalidOperation {
  unsigned      isset;  /* @thrift: isset */
  int           what;
  char *        why;
}; /* @thrift: exception */

void    ping(int sfd);
int     add(int sfd, int num1, int num2);
int     calculate_error(
        int sfd, /* @thrift: io */
        int logid,
        struct Work * w,
        int * p_res,  /* @thrift: out */
        struct InvalidOperation * p_err /* @thrift: exception */
        ); /* @thrift: calls calculate */

/* @thrift: end */

It will generate code such as:

void
ping(
        int sfd
        )
{
  int status__;
  static unsigned char send_msg0__[] = {
        0x80, 0x01, 0x00, 0x01,
        0x00, 0x00, 0x00, 0x04, 0x70, 0x69, 0x6e, 0x67,
        0x00, 0x00, 0x00, 0x00,
        0x00,
        };
  struct cthrift_rb__ rb__;
  int kind__;
if( (status__ = cthrift_write__(sfd, send_msg0__, sizeof(send_msg0__))) < 0 ){
    fprintf(stderr, "ping [%s %d]: send errro: status=%d errno=%d\n",
                __FILE__, __LINE__, status__, errno);
    exit(EXIT_FAILURE);
  }
  cthrift_init_rb__(&rb__, sfd);
  cthrift_check_rb__(&rb__, 4);
  assert(cthrift_read_be4__(rb__.p) == 0x80010002);
  cthrift_use_rb__(&rb__, 4);
  cthrift_check_rb__(&rb__, 4);
  assert(cthrift_read_be4__(rb__.p) == 0x00000004);
  cthrift_use_rb__(&rb__, 4);
  cthrift_check_rb__(&rb__, 4);
  assert( strncmp((char *)rb__.p, "ping", 4) == 0 );
  cthrift_use_rb__(&rb__, 4);
  cthrift_check_rb__(&rb__, 4);
  assert(cthrift_read_be4__(rb__.p) == 0x00000000);
  cthrift_use_rb__(&rb__, 4);
  cthrift_check_rb__(&rb__, 1);
  kind__ = cthrift_read_be1__(rb__.p);
  cthrift_use_rb__(&rb__, 1);
  while( kind__ != CTHRIFT_TYPE_STOP__ ) {
    cthrift_check_rb__(&rb__, 2);
    cthrift_use_rb__(&rb__, 2);
    cthrift_skip__(&rb__, kind__);
    cthrift_check_rb__(&rb__, 1);
    kind__ = cthrift_read_be1__(rb__.p);
    cthrift_use_rb__(&rb__, 1);
  }
}


Reply via email to