I have a thrift service method ImportantData GetImportantData()
defined in the IDL. I would like to return a Status code for this method. I would like to be doing some thing like Status GetImportantData(ImportantData&)
Is there a way to do that?
I have gone through multiple thrift tutorials like Thrift By Example
The easiest way - include Status
inside ImportantData
.
Thrift has to be portable - not every language supports output parameters (references etc.) so Thrift can't support it neither. So there can be only one returned object.
Usually best solution, providing nice future compatibility etc. is to create FunctionReturn
struct (in your example containing ImportantData
and Status
). This way some more return values can be added if needed.
BTW: if Status
is there to indicate possible errors and it will be StatusOk
most of the time, think about returning ImportantData
and throwing exceptions (which are supported by Thrift) if error occurred. Such solution would look much nicer in C++ (as always - exceptional situations - errors - should be covered by exceptions).