Avinash
Avinash

Reputation: 13257

Apache Thrift data type generalization

For the following code

struct UserProfile {
    1: i32 uid,
    2: string name,
    3: string blurb
}

service UserStorage {
    void store(1: UserProfile user),
    UserProfile retrieve(1: i32 uid)
}

Apache Thrift generates code which on the server side also refers to a UserProfile object. How can I make it to work with any custom object?

So that I can go ahead and implement the server and let the customer develop their own language client.

Upvotes: 2

Views: 268

Answers (1)

Madhawa Gunasekara
Madhawa Gunasekara

Reputation: 408

The generated Thrift files will have a file which has a Interface of service UserStorage which contains the void store(UserProfile user) and UserProfile retrieve(int uid) methods. You have to implement these methods inside the interface in your server side implementation to make your code working.

The struct UserProfile is also similar to a POJO class in Java. You will have to map the attributes of this UserProfile struct with the server side implementation attributes also to make the code work.

Please refer to the Thrift site examples for more clarification.. http://thrift.apache.org/

Upvotes: 0

Related Questions