public byte[] getCreationAttributes()
{
DynamicArray din = new DynamicArray();
bool lastGroupEmpty = true;
int attribCounter = 0;
for (int i = (creationGroups-1);i>=0;i--){
int attribOffset = i*7;
bool anyAttribEnabled = false;
byte tempHeader = 0x00;
for (int j = 6;j>=0;j--){
int position = attribOffset+j;
// This verifies that the attribute is in a group but groups has not 7 attributes
if (position<attributesCreation.Length){
Attribute temp = attributesCreation[attribOffset+j];
if (temp.isActive()){
anyAttribEnabled = true;
attribCounter++;
tempHeader = (byte) (tempHeader + (1<<j)); // Displacement
din.insertBefore(temp.getValue());
}
}
}
// Updating last attribute group, set it as 0b0XXXXXXX
if (i == (creationGroups-1)){
if (anyAttribEnabled){
din.insertBefore(tempHeader);
lastGroupEmpty = false;
}
}
// Updating other than last attribute group
else{
if (!lastGroupEmpty){
tempHeader = (byte) (tempHeader+0x80);
din.insertBefore(tempHeader);
}else{
if(anyAttribEnabled){
din.insertBefore(tempHeader);
lastGroupEmpty = false;
}
}
}
}
//add the counter of attributes sent
din.insertBefore((byte)attribCounter);
return din.getBytes();
}