public void WriteArray(object obj, Type elemType)
{
Array val = (Array)obj;
//TODO: more fast paths for primitive arrays
if (elemType == typeof (byte)) {
if (val.Length > Protocol.MaxArrayLength)
throw new Exception ("Array length " + val.Length + " exceeds maximum allowed " + Protocol.MaxArrayLength + " bytes");
Write ((uint)val.Length);
stream.Write ((byte[])val, 0, val.Length);
return;
}
long origPos = stream.Position;
Write ((uint)0);
//advance to the alignment of the element
WritePad (Protocol.GetAlignment (Signature.TypeToDType (elemType)));
long startPos = stream.Position;
foreach (object elem in val)
Write (elemType, elem);
long endPos = stream.Position;
uint ln = (uint)(endPos - startPos);
stream.Position = origPos;
if (ln > Protocol.MaxArrayLength)
throw new Exception ("Array length " + ln + " exceeds maximum allowed " + Protocol.MaxArrayLength + " bytes");
Write (ln);
stream.Position = endPos;
}