public TArray[] ReadArray <TArray> () { uint ln = ReadUInt32(); Type elemType = typeof(TArray); if (ln > ProtocolInformation.MaxArrayLength) { throw new Exception("Array length " + ln + " exceeds maximum allowed " + ProtocolInformation.MaxArrayLength + " bytes"); } //advance to the alignment of the element ReadPad(ProtocolInformation.GetAlignment(Signature.TypeToDType(elemType))); if (elemType.IsPrimitive) { // Fast path for primitive types (except bool which isn't blittable and take another path) if (elemType != typeof(bool)) { return(MarshalArray <TArray> (ln)); } else { return((TArray[])(Array)MarshalBoolArray(ln)); } } var list = new List <TArray> (); int endPos = pos + (int)ln; while (pos < endPos) { list.Add((TArray)ReadValue(elemType)); } if (pos != endPos) { throw new Exception("Read pos " + pos + " != ep " + endPos); } return(list.ToArray()); }
static int GetAlignmentFromPrimitiveType(Type type) { return(ProtocolInformation.GetAlignment(Signature.TypeCodeToDType(Type.GetTypeCode(type)))); }