Exemplo n.º 1
0
        /// <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
        }
Exemplo n.º 2
0
        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));
        }