// UTF16_BE = 19
// UTF32_LE = 20
// UTF32_BE = 21
if (machinecode < 0)
throw new PickleException("unknown machine type format");
switch (typecode) {
case 'c':// character 1 -> char[]
case 'u':// Unicode character 2 -> char[]
{
if (machinecode != 18 && machinecode != 19 && machinecode != 20 && machinecode != 21)
throw new PickleException("for c/u type must be 18/19/20/21");
if (machinecode == 18 || machinecode == 19) {
// utf-16 , 2 bytes
if (data.length % 2 != 0)
throw new PickleException("data size alignment error");
return constructCharArrayUTF16(machinecode, data);
} else {
// utf-32, 4 bytes
if (data.length % 4 != 0)
throw new PickleException("data size alignment error");
return constructCharArrayUTF32(machinecode, data);
}
}
case 'b':// signed integer 1 -> byte[]
{
if (machinecode != 1)
throw new PickleException("for b type must be 1");
return data;
}
case 'B':// unsigned integer 1 -> short[]
{
if (machinecode != 0)
throw new PickleException("for B type must be 0");
return constructShortArrayFromUByte(data);
}
case 'h':// signed integer 2 -> short[]
{
if (machinecode != 4 && machinecode != 5)
throw new PickleException("for h type must be 4/5");
if (data.length % 2 != 0)
throw new PickleException("data size alignment error");
return constructShortArraySigned(machinecode, data);
}
case 'H':// unsigned integer 2 -> int[]
{
if (machinecode != 2 && machinecode != 3)
throw new PickleException("for H type must be 2/3");
if (data.length % 2 != 0)
throw new PickleException("data size alignment error");
return constructIntArrayFromUShort(machinecode, data);
}
case 'i':// signed integer 4 -> int[]
{
if (machinecode != 8 && machinecode != 9)
throw new PickleException("for i type must be 8/9");
if (data.length % 4 != 0)
throw new PickleException("data size alignment error");
return constructIntArrayFromInt32(machinecode, data);
}
case 'l':// signed integer 4/8 -> int[]
{
if (machinecode != 8 && machinecode != 9 && machinecode != 12 && machinecode != 13)
throw new PickleException("for l type must be 8/9/12/13");
if ((machinecode==8 || machinecode==9) && (data.length % 4 != 0))
throw new PickleException("data size alignment error");
if ((machinecode==12 || machinecode==13) && (data.length % 8 != 0))
throw new PickleException("data size alignment error");
if(machinecode==8 || machinecode==9) {
//32 bits
return constructIntArrayFromInt32(machinecode, data);
} else {
//64 bits
return constructLongArrayFromInt64(machinecode, data);
}
}
case 'I':// unsigned integer 4 -> long[]
{
if (machinecode != 6 && machinecode != 7)
throw new PickleException("for I type must be 6/7");
if (data.length % 4 != 0)
throw new PickleException("data size alignment error");
return constructLongArrayFromUInt32(machinecode, data);
}
case 'L':// unsigned integer 4/8 -> long[]
{
if (machinecode != 6 && machinecode != 7 && machinecode != 10 && machinecode != 11)
throw new PickleException("for L type must be 6/7/10/11");
if ((machinecode==6 || machinecode==7) && (data.length % 4 != 0))
throw new PickleException("data size alignment error");
if ((machinecode==10 || machinecode==11) && (data.length % 8 != 0))
throw new PickleException("data size alignment error");
if(machinecode==6 || machinecode==7) {
// 32 bits
return constructLongArrayFromUInt32(machinecode, data);
} else {
// 64 bits
return constructLongArrayFromUInt64(machinecode, data);
}
}
case 'f':// floating point 4 -> float[]
{
if (machinecode != 14 && machinecode != 15)
throw new PickleException("for f type must be 14/15");
if (data.length % 4 != 0)
throw new PickleException("data size alignment error");
return constructFloatArray(machinecode, data);
}
case 'd':// floating point 8 -> double[]
{
if (machinecode != 16 && machinecode != 17)
throw new PickleException("for d type must be 16/17");
if (data.length % 8 != 0)
throw new PickleException("data size alignment error");
return constructDoubleArray(machinecode, data);
}
default:
throw new PickleException("invalid array typecode: " + typecode);
}
}