简体   繁体   中英

How to return more than one value in a Thrift service method?

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM