Byte is a list or an array? CTl2

function string shadeColor(string color, integer idx)
{
string res;
res = replace(color,“#”,“”);
byte b = hex2byte(res);
for (integer i=0;i<length(b);i++)
{
b[i] = bitOr(b[i], bitLShift(1, idx)); //Error: expression is not a composite type but is resolved to byte
}
res = “#” + byte2hex(b);
return res;
}

i can’t catch the concept of byte type, help me

Unfortunately, as of Clover version 3.5 the byte data type does not allow to access individual byte values in the array using index:

b[i] = 1; //this is not valid

We will fix this issue in the future version, but for now, following two options are available for you:

Custom Java transformation example:


import org.jetel.component.DataRecordTransform;
import org.jetel.data.DataRecord;
import org.jetel.exception.ComponentNotReadyException;
import org.jetel.exception.TransformException;

public class ColorTrans extends DataRecordTransform {

	@Override
	public boolean init() throws ComponentNotReadyException {
		return super.init();
	}

	@Override
	public int transform(DataRecord[] arg0, DataRecord[] arg1)
			throws TransformException {

		byte[] bytearray;
		
		// get source value
		String value=arg0[0].getField("myfieldStr").toString();
		
		// do some manipulation
		bytearray = value.getBytes();
		
		//set result to output
		arg1[0].getField("myoutputBye").setValue(bytearray);
		
		return OK; //next record
	}

}