Friday, May 16, 2014

Thrift: language independent communication of Android to Linux box


This document describes programming language-independent, e.g.:

  • Java to C++, 
  • Java to Python, 
  • Java to Java 
communication between Android and Linux server (i.e. Mac, Raspberry Pi, BeagleBone Black).

Installing Thrift Compiler

On Debian Linux:
apt-get install thrift-compiler

On Mac:

$ brew install thrift
==> Installing thrift dependency: boost...==>
Summary /usr/local/Cellar/thrift/0.9.1: 89 files, 4.8M, built in 2.8 minutes

Creating Thrift Definition File

namespace java
service MyService {
    bool enableMethod();
    bool disableMethod();

Generate Sources from Thrift Definition File

$ thrift --gen java -out gen ./src/main/thrift/definition_file.thrift

This line tells Thrift
  • --gen java - generate Java files (change for C++, etc.)
  • -out gen - put output files in "gen" folder
  • ./src... .thrift - use this definition file