in proton-j/src/main/java/org/apache/qpid/proton/codec/ArrayType.java [195:282]
private static int calculateSize(final Object[] val, final TypeEncoding encoder)
{
int size = encoder.getConstructorSize();
if(encoder.isFixedSizeVal())
{
size += val.length * encoder.getValueSize(null);
}
else
{
for(Object o : val)
{
if(o.getClass().isArray() && o.getClass().getComponentType().isPrimitive())
{
ArrayEncoding arrayEncoding = (ArrayEncoding) encoder;
ArrayType arrayType = (ArrayType) arrayEncoding.getType();
Class componentType = o.getClass().getComponentType();
size += 2 * arrayEncoding.getSizeBytes();
TypeEncoding componentEncoding;
int componentCount;
if(componentType == Boolean.TYPE)
{
boolean[] componentArray = (boolean[]) o;
componentEncoding = arrayType.getUnderlyingEncoding(componentArray);
componentCount = componentArray.length;
}
else if(componentType == Byte.TYPE)
{
byte[] componentArray = (byte[]) o;
componentEncoding = arrayType.getUnderlyingEncoding(componentArray);
componentCount = componentArray.length;
}
else if(componentType == Short.TYPE)
{
short[] componentArray = (short[]) o;
componentEncoding = arrayType.getUnderlyingEncoding(componentArray);
componentCount = componentArray.length;
}
else if(componentType == Integer.TYPE)
{
int[] componentArray = (int[]) o;
componentEncoding = arrayType.getUnderlyingEncoding(componentArray);
componentCount = componentArray.length;
}
else if(componentType == Long.TYPE)
{
long[] componentArray = (long[]) o;
componentEncoding = arrayType.getUnderlyingEncoding(componentArray);
componentCount = componentArray.length;
}
else if(componentType == Float.TYPE)
{
float[] componentArray = (float[]) o;
componentEncoding = arrayType.getUnderlyingEncoding(componentArray);
componentCount = componentArray.length;
}
else if(componentType == Double.TYPE)
{
double[] componentArray = (double[]) o;
componentEncoding = arrayType.getUnderlyingEncoding(componentArray);
componentCount = componentArray.length;
}
else if(componentType == Character.TYPE)
{
char[] componentArray = (char[]) o;
componentEncoding = arrayType.getUnderlyingEncoding(componentArray);
componentCount = componentArray.length;
}
else
{
throw new IllegalArgumentException("Cannot encode arrays of type " + componentType.getName());
}
size += componentEncoding.getConstructorSize()
+ componentEncoding.getValueSize(null) * componentCount;
}
else
{
size += encoder.getValueSize(o);
}
}
}
return size;
}