use of org.ballerinalang.util.codegen.StructInfo in project ballerina by ballerina-lang.
the class BTestUtils method createAndGetStruct.
public static BStruct createAndGetStruct(ProgramFile programFile, String packagePath, String structName) {
PackageInfo structPackageInfo = programFile.getPackageInfo(packagePath);
StructInfo structInfo = structPackageInfo.getStructInfo(structName);
BStructType structType = structInfo.getType();
return new BStruct(structType);
}
use of org.ballerinalang.util.codegen.StructInfo in project ballerina by ballerina-lang.
the class Utils method createSpanStruct.
public static BStruct createSpanStruct(Context context, String spanId, String serviceName, String spanName) {
PackageInfo observePackage = context.getProgramFile().getPackageInfo("ballerina.observe");
StructInfo spanStructInfo = observePackage.getStructInfo("Span");
return BLangVMStructs.createBStruct(spanStructInfo, spanId, serviceName, spanName);
}
use of org.ballerinalang.util.codegen.StructInfo in project ballerina by ballerina-lang.
the class TransactionUtils method checkTransactionCoordinatorError.
private static void checkTransactionCoordinatorError(BValue value, WorkerExecutionContext ctx, String errMsg) {
if (value.getType().getTag() == TypeTags.STRUCT_TAG) {
PackageInfo errorPackageInfo = ctx.programFile.getPackageInfo(PACKAGE_BUILTIN);
StructInfo errorStructInfo = errorPackageInfo.getStructInfo(STRUCT_GENERIC_ERROR);
if (((BStruct) value).getType().structInfo.equals(errorStructInfo)) {
throw new BallerinaException(errMsg + ((BStruct) value).getStringField(0));
}
}
}
use of org.ballerinalang.util.codegen.StructInfo in project ballerina by ballerina-lang.
the class OpenSecureSocket method createReturnStruct.
private BStruct createReturnStruct(Context context, SSLSocket sslSocket, ByteChannel channel) throws IOException {
PackageInfo ioPackageInfo = context.getProgramFile().getPackageInfo(SOCKET_PACKAGE);
// Create ByteChannel Struct
StructInfo channelStructInfo = ioPackageInfo.getStructInfo(BYTE_CHANNEL_STRUCT_TYPE);
Channel ballerinaSocketChannel = new SocketIOChannel(channel, 0);
BStruct channelStruct = BLangVMStructs.createBStruct(channelStructInfo, ballerinaSocketChannel);
channelStruct.addNativeData(IOConstants.BYTE_CHANNEL_NAME, ballerinaSocketChannel);
// Create Socket Struct
StructInfo socketStructInfo = ioPackageInfo.getStructInfo(SOCKET_STRUCT_TYPE);
BStruct socketStruct = BLangVMStructs.createBStruct(socketStructInfo);
socketStruct.setRefField(0, channelStruct);
socketStruct.setIntField(0, sslSocket.getPort());
socketStruct.setIntField(1, sslSocket.getLocalPort());
socketStruct.setStringField(0, sslSocket.getInetAddress().getHostAddress());
socketStruct.setStringField(1, sslSocket.getLocalAddress().getHostAddress());
socketStruct.addNativeData(IOConstants.CLIENT_SOCKET_NAME, channel);
return socketStruct;
}
use of org.ballerinalang.util.codegen.StructInfo in project ballerina by ballerina-lang.
the class ParseTo method execute.
@Override
public void execute(Context context) {
String dateString = context.getStringArgument(0);
BEnumerator pattern = (BEnumerator) context.getRefArgument(0);
TemporalAccessor parsedDateTime;
switch(pattern.getName()) {
case "RFC_1123":
parsedDateTime = DateTimeFormatter.RFC_1123_DATE_TIME.parse(dateString);
break;
default:
throw new BallerinaException("failed to parse date/time string: " + dateString);
}
StructInfo timeZoneStructInfo = Utils.getTimeZoneStructInfo(context);
StructInfo timeStructInfo = Utils.getTimeStructInfo(context);
long epochTime = -1;
String zoneId;
try {
epochTime = Instant.from(parsedDateTime).toEpochMilli();
zoneId = String.valueOf(ZoneId.from(parsedDateTime));
} catch (DateTimeException e) {
if (epochTime < 0) {
throw new BallerinaException("failed to parse \"" + dateString + "\" to the " + pattern.getName() + " format");
}
zoneId = ZoneId.systemDefault().toString();
}
BStruct timeStruct = Utils.createTimeStruct(timeZoneStructInfo, timeStructInfo, epochTime, zoneId);
context.setReturnValues(timeStruct);
}
Aggregations