Search in sources :

Example 16 with BBlob

use of org.ballerinalang.model.values.BBlob in project ballerina by ballerina-lang.

the class Debugger method generateDebugHitMessage.

/**
 * Generate debug hit message.
 *
 * @param ctx               Current context.
 * @param currentExecLine   Current execution line.
 * @param workerId          Current thread id.
 * @return  message         To be sent.
 */
private MessageDTO generateDebugHitMessage(WorkerExecutionContext ctx, LineNumberInfo currentExecLine, String workerId) {
    MessageDTO message = new MessageDTO(DebugConstants.CODE_HIT, DebugConstants.MSG_HIT);
    message.setThreadId(workerId);
    BreakPointDTO breakPointDTO = new BreakPointDTO(currentExecLine.getPackageInfo().getPkgPath(), currentExecLine.getFileName(), currentExecLine.getLineNumber());
    message.setLocation(breakPointDTO);
    int callingIp = currentExecLine.getIp();
    String pck = ctx.callableUnitInfo.getPackageInfo().getPkgPath();
    String functionName = ctx.callableUnitInfo.getName();
    LineNumberInfo callingLine = getLineNumber(ctx.callableUnitInfo.getPackageInfo().getPkgPath(), callingIp);
    FrameDTO frameDTO = new FrameDTO(pck, functionName, callingLine.getFileName(), callingLine.getLineNumber());
    message.addFrame(frameDTO);
    LocalVariableAttributeInfo localVarAttrInfo = (LocalVariableAttributeInfo) ctx.workerInfo.getAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE);
    localVarAttrInfo.getLocalVariables().forEach(l -> {
        VariableDTO variableDTO = new VariableDTO(l.getVariableName(), "Local");
        switch(l.getVariableType().getTag()) {
            case TypeTags.INT_TAG:
                variableDTO.setBValue(new BInteger(ctx.workerLocal.longRegs[l.getVariableIndex()]));
                break;
            case TypeTags.FLOAT_TAG:
                variableDTO.setBValue(new BFloat(ctx.workerLocal.doubleRegs[l.getVariableIndex()]));
                break;
            case TypeTags.STRING_TAG:
                variableDTO.setBValue(new BString(ctx.workerLocal.stringRegs[l.getVariableIndex()]));
                break;
            case TypeTags.BOOLEAN_TAG:
                variableDTO.setBValue(new BBoolean(ctx.workerLocal.intRegs[l.getVariableIndex()] == 1));
                break;
            case TypeTags.BLOB_TAG:
                variableDTO.setBValue(new BBlob(ctx.workerLocal.byteRegs[l.getVariableIndex()]));
                break;
            default:
                variableDTO.setBValue(ctx.workerLocal.refRegs[l.getVariableIndex()]);
                break;
        }
        frameDTO.addVariable(variableDTO);
    });
    return message;
}
Also used : BreakPointDTO(org.ballerinalang.util.debugger.dto.BreakPointDTO) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BBoolean(org.ballerinalang.model.values.BBoolean) BString(org.ballerinalang.model.values.BString) MessageDTO(org.ballerinalang.util.debugger.dto.MessageDTO) LocalVariableAttributeInfo(org.ballerinalang.util.codegen.attributes.LocalVariableAttributeInfo) VariableDTO(org.ballerinalang.util.debugger.dto.VariableDTO) BFloat(org.ballerinalang.model.values.BFloat) LineNumberInfo(org.ballerinalang.util.codegen.LineNumberInfo) BBlob(org.ballerinalang.model.values.BBlob) FrameDTO(org.ballerinalang.util.debugger.dto.FrameDTO)

Example 17 with BBlob

use of org.ballerinalang.model.values.BBlob in project ballerina by ballerina-lang.

the class BBlobValueTest method testBlobField.

@Test(description = "Test blob global variable")
public void testBlobField() {
    byte[] bytes = "string".getBytes();
    BValue[] args = { new BBlob(bytes) };
    BValue[] returns = BRunUtil.invoke(result, "testBlobField", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BBlob.class);
    BBlob blob = (BBlob) returns[0];
    Assert.assertEquals(blob.blobValue(), bytes, "Invalid byte value returned.");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BBlob(org.ballerinalang.model.values.BBlob) Test(org.testng.annotations.Test)

Example 18 with BBlob

use of org.ballerinalang.model.values.BBlob in project ballerina by ballerina-lang.

the class BBlobValueTest method testBlobParameter.

@Test(description = "Test blob value assignment")
public void testBlobParameter() {
    byte[] bytes = "string".getBytes();
    BValue[] args = { new BBlob(bytes) };
    BValue[] returns = BRunUtil.invoke(result, "testBlobParameter", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BBlob.class);
    BBlob blob = (BBlob) returns[0];
    Assert.assertEquals(blob.blobValue(), bytes, "Invalid byte value returned.");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BBlob(org.ballerinalang.model.values.BBlob) Test(org.testng.annotations.Test)

Example 19 with BBlob

use of org.ballerinalang.model.values.BBlob in project ballerina by ballerina-lang.

the class BlobTest method testToString.

@Test(description = "Get string representation of blob")
public void testToString() throws UnsupportedEncodingException {
    BValue[] args = { new BBlob(content.getBytes("UTF-8")), new BString("UTF-8") };
    BValue[] returns = BRunUtil.invoke(result, "toString", args);
    final String expected = content;
    Assert.assertEquals(returns[0].stringValue(), expected);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BString(org.ballerinalang.model.values.BString) BBlob(org.ballerinalang.model.values.BBlob) Test(org.testng.annotations.Test)

Example 20 with BBlob

use of org.ballerinalang.model.values.BBlob in project ballerina by ballerina-lang.

the class MimeUtilityFunctionTest method testMimeBase64Encode.

@Test(description = "Test 'testMimeBase64Encode' function in ballerina.mime package")
public void testMimeBase64Encode() {
    BBlob blob = new BBlob("a".getBytes());
    BValue[] args = { blob };
    BValue[] returns = BRunUtil.invoke(compileResult, "testMimeBase64Encode", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertEquals(returns[0].stringValue(), "YQ==");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BBlob(org.ballerinalang.model.values.BBlob) Test(org.testng.annotations.Test)

Aggregations

BBlob (org.ballerinalang.model.values.BBlob)32 BValue (org.ballerinalang.model.values.BValue)23 Test (org.testng.annotations.Test)19 BString (org.ballerinalang.model.values.BString)16 BInteger (org.ballerinalang.model.values.BInteger)11 BBoolean (org.ballerinalang.model.values.BBoolean)6 BFloat (org.ballerinalang.model.values.BFloat)6 BStruct (org.ballerinalang.model.values.BStruct)5 BType (org.ballerinalang.model.types.BType)4 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)3 ByteBuffer (java.nio.ByteBuffer)2 Base64 (java.util.Base64)2 BJSON (org.ballerinalang.model.values.BJSON)2 BRefType (org.ballerinalang.model.values.BRefType)2 BlobDataSource (org.ballerinalang.runtime.message.BlobDataSource)2 MessageDataSource (org.ballerinalang.runtime.message.MessageDataSource)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 CRC32 (java.util.zip.CRC32)1 Checksum (java.util.zip.Checksum)1 Context (org.ballerinalang.bre.Context)1