/// <summary> /// Initializes a new instance of the <see cref="T:ndf5.Messages.ArrayType"/> class. /// </summary> /// <param name="aHeader">IDatatypeHeader with the basic data about this type</param> /// <param name="aDimensionSizes">Size of each dimension in this array</param> /// <param name="aBaseType">Type of the data elements of this array</param> public ArrayDataType( IDatatypeHeader aHeader, uint[] aDimensionSizes, Datatype aBaseType) : this(aDimensionSizes, aBaseType, aHeader.Size) { if (aHeader.Class != DatatypeClass.Array) { throw new ArgumentException( $"Header Class must be {nameof(DatatypeClass.Array)}", nameof(aHeader)); } }
/// <summary> /// Initializes a new instance of the <see cref="T:ndf5.Messages.ArrayType"/> class. /// </summary> /// <param name="aSize">The size in bytes of this array</param> /// <param name="aDimensionSizes">Size of each dimension in this array</param> /// <param name="aBaseType">Type of the data elements of this array</param> public ArrayDataType( uint[] aDimensionSizes, Datatype aBaseType, uint?aSize = null) : base( DatatypeClass.Array, aSize ?? (aDimensionSizes.Any(a => a == 0) ? 1 : aBaseType.Size * aDimensionSizes.Aggregate( (uint) 1, (uint arg1, uint arg2) => arg1 * arg2))) { mrDimensionSizes = aDimensionSizes; mrBaseType = aBaseType; }
public MemberEntry( string aName, Datatype aDataType, ulong aByteOffset) { if (aName.IsNull()) { throw new ArgumentNullException(nameof(aName)); } if (aDataType.IsNull()) { throw new ArgumentNullException(nameof(aDataType)); } Name = aName; Datatype = aDataType; ByteOffset = aByteOffset; }
/// <summary> /// Reads the message at the current location of an Hdf5Reader /// </summary> /// <returns>The message.</returns> /// <param name="aReader">A reader.</param> /// <param name="aReadFlags">Flags that describe how to handle this message</param> /// <param name="aMessageType">Type of message to read</param> /// <param name="aLocalMessageSize">Number of bytes to read</param> /// <param name="aBytes">Number of bytes that were actually read</param> public static Message Read( Hdf5Reader aReader, MessageType aMessageType, MessageAttributeFlag aReadFlags, long?aLocalMessageSize, out long aBytes) { switch (aMessageType) { case MessageType.NIL: aBytes = 0; return(new Nil()); case MessageType.Dataspace: return(Dataspace.Read( aReader, aLocalMessageSize, out aBytes)); case MessageType.LinkInfo: return(LinkInfo.Read( aReader, aLocalMessageSize, out aBytes)); case MessageType.Datatype: return(Datatype.Read( aReader, aLocalMessageSize, out aBytes)); default: if (aReadFlags.HasFlag(MessageAttributeFlag.MustUnderstandToRead)) { throw new Exceptions.RequiredMessageNotUnderstood( $"Message type {aMessageType} must be understood for this object to be valid"); } break; } throw new NotImplementedException();//TODO: Add 'Not Undestood' message }
internal static Datatype ReadMessage( DatatypeHeader aHeader, Hdf5Reader aReader, long?aLocalMessageSize, out long aBytes) { if (aHeader.Class != DatatypeClass.Array) { throw new ArgumentException( $"aHeader must be for type {nameof(DatatypeClass.Array)}"); } bool fReadPermutaions; long fSize = sizeof(uint); switch (aHeader.Version) { case DatatypeVersion.Version1: throw new UnknownMessageVersion <ArrayDataType>( (int)aHeader.Version, "Arrays are not supported in verion 1"); case DatatypeVersion.Version2: fReadPermutaions = true; break; default: fReadPermutaions = false; break; } byte fDimensionality = aReader.ReadByte(); aReader.Seek(3, System.IO.SeekOrigin.Current); // Reserved bytes uint[] fDimeensions = Enumerable .Range(0, fDimensionality) .Select(a => aReader.ReadUInt32()) .ToArray(); fSize += fDimensionality * sizeof(uint); if (fReadPermutaions) { if (!Enumerable.Range(0, fDimeensions.Length).All(a => a == aReader.ReadUInt32())) { throw new Hdf5UnsupportedFeature("Custom permutations not supported"); } fSize += fDimensionality * sizeof(uint); } long? fBaseLocalmessageSize = aLocalMessageSize; if (fBaseLocalmessageSize.HasValue) { fBaseLocalmessageSize -= fSize; } long fBaseTypeSize; Datatype fBaseType = Datatype.Read(aReader, fBaseLocalmessageSize, out fBaseTypeSize); aBytes = fSize + fBaseTypeSize; return(new ArrayDataType(aHeader, fDimeensions, fBaseType)); }