use of org.ballerinalang.model.types.BType in project ballerina by ballerina-lang.
the class BLangVMUtils method createReturnRegValues.
public static int[] createReturnRegValues(WorkerDataIndex paramWDI, WorkerDataIndex retWDI, BType[] retTypes) {
int[] result = new int[retWDI.retRegs.length];
System.arraycopy(retWDI.retRegs, 0, result, 0, result.length);
for (int i = 0; i < result.length; i++) {
BType retType = retTypes[i];
switch(retType.getTag()) {
case TypeTags.INT_TAG:
result[i] += paramWDI.longRegCount;
break;
case TypeTags.FLOAT_TAG:
result[i] += paramWDI.doubleRegCount;
break;
case TypeTags.STRING_TAG:
result[i] += paramWDI.stringRegCount;
break;
case TypeTags.BOOLEAN_TAG:
result[i] += paramWDI.intRegCount;
break;
case TypeTags.BLOB_TAG:
result[i] += paramWDI.byteRegCount;
break;
default:
result[i] += paramWDI.refRegCount;
break;
}
}
return result;
}
use of org.ballerinalang.model.types.BType in project ballerina by ballerina-lang.
the class BLangVMUtils method mergeResultData.
public static void mergeResultData(WorkerData sourceData, WorkerData targetData, BType[] types, int[] regIndexes) {
int callersRetRegIndex;
int longRegCount = 0;
int doubleRegCount = 0;
int stringRegCount = 0;
int intRegCount = 0;
int refRegCount = 0;
int byteRegCount = 0;
for (int i = 0; i < types.length; i++) {
BType retType = types[i];
callersRetRegIndex = regIndexes[i];
switch(retType.getTag()) {
case TypeTags.INT_TAG:
targetData.longRegs[callersRetRegIndex] = sourceData.longRegs[longRegCount++];
break;
case TypeTags.FLOAT_TAG:
targetData.doubleRegs[callersRetRegIndex] = sourceData.doubleRegs[doubleRegCount++];
break;
case TypeTags.STRING_TAG:
targetData.stringRegs[callersRetRegIndex] = sourceData.stringRegs[stringRegCount++];
break;
case TypeTags.BOOLEAN_TAG:
targetData.intRegs[callersRetRegIndex] = sourceData.intRegs[intRegCount++];
break;
case TypeTags.BLOB_TAG:
targetData.byteRegs[callersRetRegIndex] = sourceData.byteRegs[byteRegCount++];
break;
default:
targetData.refRegs[callersRetRegIndex] = sourceData.refRegs[refRegCount++];
break;
}
}
}
use of org.ballerinalang.model.types.BType in project ballerina by ballerina-lang.
the class BLangVMUtils method populateReturnData.
public static BValue[] populateReturnData(WorkerExecutionContext ctx, CallableUnitInfo callableUnitInfo, int[] retRegs) {
WorkerData data = ctx.workerLocal;
BType[] retTypes = callableUnitInfo.getRetParamTypes();
BValue[] returnValues = new BValue[retTypes.length];
for (int i = 0; i < returnValues.length; i++) {
BType retType = retTypes[i];
switch(retType.getTag()) {
case TypeTags.INT_TAG:
returnValues[i] = new BInteger(data.longRegs[retRegs[i]]);
break;
case TypeTags.FLOAT_TAG:
returnValues[i] = new BFloat(data.doubleRegs[retRegs[i]]);
break;
case TypeTags.STRING_TAG:
returnValues[i] = new BString(data.stringRegs[retRegs[i]]);
break;
case TypeTags.BOOLEAN_TAG:
boolean boolValue = data.intRegs[retRegs[i]] == 1;
returnValues[i] = new BBoolean(boolValue);
break;
case TypeTags.BLOB_TAG:
returnValues[i] = new BBlob(data.byteRegs[retRegs[i]]);
break;
default:
returnValues[i] = data.refRegs[retRegs[i]];
break;
}
}
return returnValues;
}
use of org.ballerinalang.model.types.BType in project ballerina by ballerina-lang.
the class MethodListener method getRequestParameter.
/**
* Returns BValue object corresponding to the protobuf request message.
*
* @param requestMessage protobuf request message.
* @return b7a message.
*/
BValue getRequestParameter(Resource resource, Message requestMessage) {
if (resource == null || resource.getParamDetails() == null || resource.getParamDetails().size() > 2) {
throw new RuntimeException("Invalid resource input arguments. arguments must not be greater than two");
}
if (resource.getParamDetails().size() == 2) {
BType requestType = resource.getParamDetails().get(MessageConstants.REQUEST_MESSAGE_PARAM_INDEX).getVarType();
String requestName = resource.getParamDetails().get(MessageConstants.REQUEST_MESSAGE_PARAM_INDEX).getVarName();
return generateRequestStruct(requestMessage, getProgramFile(resource), requestName, requestType);
} else {
return null;
}
}
use of org.ballerinalang.model.types.BType in project ballerina by ballerina-lang.
the class DefaultStreamObserver method onError.
@Override
public void onError(Throwable t) {
Resource onError = resourceMap.get(MessageConstants.ON_ERROR_RESOURCE);
if (onError == null) {
String message = "Error in listener service definition. onError resource does not exists";
LOG.error(message);
throw new RuntimeException(message);
}
List<ParamDetail> paramDetails = onError.getParamDetails();
BValue[] signatureParams = new BValue[paramDetails.size()];
if (paramDetails.size() != 1) {
String message = "Error in onError resource definition. It must have only error params, but have " + paramDetails.size();
LOG.error(message);
throw new RuntimeException(message);
}
BType errorType = paramDetails.get(1).getVarType();
BStruct errorStruct = MessageUtils.getConnectorError((BStructType) errorType, t);
signatureParams[0] = errorStruct;
CallableUnitCallback callback = new GrpcCallableUnitCallBack(null);
Executor.submit(onError, callback, null, null, signatureParams);
}
Aggregations