public static ResponseStatus fromBinary ( final short code ) { KeyValueStatus status = KeyValueStatus . valueOf ( code ) ; switch ( status ) { case SUCCESS : return ResponseStatus . SUCCESS ; case ERR_EXISTS : return ResponseStatus . EXISTS ; case ERR_NOT_FOUND : return ResponseStatus . NOT_EXISTS ; case ERR_NOT_MY_VBUCKET : return ResponseStatus . RETRY ; case ERR_NOT_STORED : return ResponseStatus . NOT_STORED ; case ERR_TOO_BIG : return ResponseStatus . TOO_BIG ; case ERR_TEMP_FAIL : return ResponseStatus . TEMPORARY_FAILURE ; case ERR_BUSY : return ResponseStatus . SERVER_BUSY ; case ERR_NO_MEM : return ResponseStatus . OUT_OF_MEMORY ; case ERR_UNKNOWN_COMMAND : return ResponseStatus . COMMAND_UNAVAILABLE ; case ERR_NOT_SUPPORTED : return ResponseStatus . COMMAND_UNAVAILABLE ; case ERR_ACCESS : return ResponseStatus . ACCESS_ERROR ; case ERR_INTERNAL : return ResponseStatus . INTERNAL_ERROR ; case ERR_INVALID : return ResponseStatus . INVALID_ARGUMENTS ; case ERR_DELTA_BADVAL : return ResponseStatus . INVALID_ARGUMENTS ; case ERR_RANGE : return ResponseStatus . RANGE_ERROR ; case ERR_ROLLBACK : return ResponseStatus . ROLLBACK ; //== the following codes are for subdocument API == case ERR_SUBDOC_PATH_NOT_FOUND : return ResponseStatus . SUBDOC_PATH_NOT_FOUND ; case ERR_SUBDOC_PATH_MISMATCH : return ResponseStatus . SUBDOC_PATH_MISMATCH ; case ERR_SUBDOC_PATH_INVALID : return ResponseStatus . SUBDOC_PATH_INVALID ; case ERR_SUBDOC_PATH_TOO_BIG : return ResponseStatus . SUBDOC_PATH_TOO_BIG ; case ERR_SUBDOC_DOC_TOO_DEEP : return ResponseStatus . SUBDOC_DOC_TOO_DEEP ; case ERR_SUBDOC_VALUE_CANTINSERT : return ResponseStatus . SUBDOC_VALUE_CANTINSERT ; case ERR_SUBDOC_DOC_NOT_JSON : return ResponseStatus . SUBDOC_DOC_NOT_JSON ; case ERR_SUBDOC_NUM_RANGE : return ResponseStatus . SUBDOC_NUM_RANGE ; case ERR_SUBDOC_DELTA_RANGE : return ResponseStatus . SUBDOC_DELTA_RANGE ; case ERR_SUBDOC_PATH_EXISTS : return ResponseStatus . SUBDOC_PATH_EXISTS ; case ERR_SUBDOC_VALUE_TOO_DEEP : return ResponseStatus . SUBDOC_VALUE_TOO_DEEP ; case ERR_SUBDOC_INVALID_COMBO : return ResponseStatus . SUBDOC_INVALID_COMBO ; case ERR_SUBDOC_MULTI_PATH_FAILURE : return ResponseStatus . SUBDOC_MULTI_PATH_FAILURE ; case ERR_SUBDOC_XATTR_INVALID_FLAG_COMBO : return ResponseStatus . INTERNAL_ERROR ; case ERR_SUBDOC_XATTR_UNKNOWN_MACRO : return ResponseStatus . SUBDOC_XATTR_UNKNOWN_MACRO ; case ERR_SUBDOC_XATTR_INVALID_KEY_COMBO : return ResponseStatus . SUBDOC_XATTR_INVALID_KEY_COMBO ; //== end of subdocument API codes == } return ResponseStatus . FAILURE ; }
Convert the binary protocol status in a typesafe enum that can be acted upon later .