You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Ashish Tanwar <as...@yahoo.com.INVALID> on 2015/09/17 21:29:59 UTC
Parsing method name from MemoryBuffer ...?
Hi,
I am trying to use Thrift over Xmpp chat. The code example is in java.
Consider the example thrift.
service Api
{
string hello(1: string message),
string hello2(1: string message, 2: string message2),
}
While calling, i am using memory buffer to use xmpp tarnsport
transport_in = new TMemoryBuffer(0);
transport_out = new TMemoryBuffer(0);
protocol_in = new TJSONProtocol(transport_in);
protocol_out = new TJSONProtocol(transport_out);
Message msg = new Message();
client = new Api.Client(protocol_in, protocol_out);
client.send_hello("Hello");
msg.setBody(transport_out.toString("UTF-8"));
newChat.sendMessage(msg);
Response comes in Xmpp message reply :
public void processMessage(Chat chat, Message message)
{
try
{
client.getInputProtocol().getTransport().write(message.getBody().getBytes());
System.out.println("Received message: " + client.recv_hello());
}
catch (Exception ex)
{
Logger.getLogger(SimpleXmppMessage.class.getName()).log(Level.INFO,
null, ex);
}
}
Is there a way to make out the method name for which response is
received ? Something like
switch(message.getBody().getBytes()..(method_id))
{
case hello:
process_hello(message.getBody().getBytes());
break;
case hello2:
process_hello2(message.getBody().getBytes());
break;
}
One solution can be to maintain maintain a hashmap of message_id in xmpp
vs thrift RPC method.
However, if it can be handled in thrift payload, it would make solution
elegant. Any pointers?
Regards.
Ashish