Esempio n. 1
0
        internal static Datatype ReadMessage(
            DatatypeHeader aHeader,
            Hdf5Reader aReader,
            long?aLocalMessageSize,
            out long aBytes)
        {
            if (aHeader.Class != DatatypeClass.Time)
            {
                throw new ArgumentException(
                          $"aHeader must be for type {nameof(DatatypeClass.Time)}");
            }

            if (aLocalMessageSize.HasValue && aLocalMessageSize < mcAddionalSize)
            {
                throw new ArgumentException("Specified Local Message Size not long enough");
            }

            Flags fFlags = (Flags)aHeader.Flags;

            ByteOrdering
                fByteOrdering = fFlags.HasFlag(Flags.BigEndian)
                    ? ByteOrdering.BigEndian
                    : ByteOrdering.LittleEndian;
            uint
                fBitPrecision = aReader.ReadUInt32();

            aBytes = mcAddionalSize;
            return(new TimeDataType(
                       aHeader,
                       fByteOrdering,
                       fBitPrecision));
        }
Esempio n. 2
0
        internal static Datatype ReadMessage(
            DatatypeHeader aHeader,
            Hdf5Reader aReader,
            long?aLocalMessageSize,
            out long aBytes)
        {
            if (aHeader.Class != DatatypeClass.Opaque)
            {
                throw new ArgumentException(
                          $"aHeader must be for type {nameof(DatatypeClass.Compound)}");
            }

            int
                fTagSize = (int)aHeader.Flags & byte.MaxValue;

            if (aLocalMessageSize.HasValue && aLocalMessageSize < fTagSize)
            {
                throw new ArgumentException("Specified Local Message Size not long enough");
            }

            aBytes = fTagSize;

            IEnumerable <MemberEntry>
            fMembers = null;



            return(new CompoundDataType(
                       aHeader,
                       fMembers));
        }
Esempio n. 3
0
        internal static Datatype ReadMessage(
            DatatypeHeader aHeader,
            Hdf5Reader aReader,
            long?aLocalMessageSize,
            out long aBytes)
        {
            if (aHeader.Class != DatatypeClass.FixedPoint)
            {
                throw new ArgumentException(
                          $"aHeader must be for type {nameof(DatatypeClass.FixedPoint)}");
            }

            if (aLocalMessageSize.HasValue && aLocalMessageSize < mcAddionalSize)
            {
                throw new ArgumentException("Specified Local Message Size not long enough");
            }

            Flags fFlags = (Flags)aHeader.Flags;

            ByteOrdering
                fByteOrdering = fFlags.HasFlag(Flags.BigEndian)
                    ? ByteOrdering.BigEndian
                    : ByteOrdering.LittleEndian;
            byte
                fLowPad  = (byte)(fFlags.HasFlag(Flags.LowPad) ? 1 : 0),
                fHighPad = (byte)(fFlags.HasFlag(Flags.HighPad) ? 1 : 0);
            bool
                fIsSigned = fFlags.HasFlag(Flags.Signed);

            ushort
                fBitOffset    = aReader.ReadUInt16(),
                fBitPrecision = aReader.ReadUInt16();

            aBytes = mcAddionalSize;
            return(new FixedPointDataType(
                       aHeader,
                       fByteOrdering,
                       fHighPad,
                       fLowPad,
                       fIsSigned,
                       fBitOffset,
                       fBitPrecision));
        }
Esempio n. 4
0
        internal static Datatype ReadMessage(
            DatatypeHeader aHeader,
            Hdf5Reader aReader,
            long?aLocalMessageSize,
            out long aBytes)
        {
            if (aHeader.Class != DatatypeClass.Opaque)
            {
                throw new ArgumentException(
                          $"aHeader must be for type {nameof(DatatypeClass.Opaque)}");
            }

            int
                fTagSize = (int)aHeader.Flags & byte.MaxValue;

            if (aLocalMessageSize.HasValue && aLocalMessageSize < fTagSize)
            {
                throw new ArgumentException("Specified Local Message Size not long enough");
            }

            byte[]
            fTagBytes = new byte[fTagSize];

            int
                fReadByteCount = aReader.Read(fTagBytes, 0, fTagSize);

            if (fReadByteCount != fTagSize)
            {
                throw new EndOfStreamException("Could not read entire Opaque data type");
            }

            String
                fAsciiTag = Encoding.ASCII.GetString(fTagBytes).TrimEnd((char)0);

            aBytes = fTagSize;

            return(new OpaqueDataType(
                       aHeader,
                       fAsciiTag));
        }
Esempio n. 5
0
        internal static Datatype ReadMessage(
            DatatypeHeader aHeader,
            Hdf5Reader aReader,
            long?aLocalMessageSize,
            out long aBytes)
        {
            if (aHeader.Class != DatatypeClass.String)
            {
                throw new ArgumentException(
                          $"aHeader must be for type {nameof(DatatypeClass.String)}");
            }

            if (aLocalMessageSize.HasValue && aLocalMessageSize < 0)
            {
                throw new ArgumentException("Specified Local Message Size not long enough");
            }

            byte
                fStringPadding  = (byte)(aHeader.Flags & 0x0F),
                fStringEncoding = (byte)((aHeader.Flags & 0xF0) >> 4);

            if (fStringPadding > (byte)StringPadding.SpacePad)
            {
                throw new ArgumentException($"Invalid {nameof(StringPadding)}: {fStringPadding}");
            }
            if (fStringEncoding > (byte)StringEncoding.UTF8)
            {
                throw new ArgumentException($"Invalid {nameof(StringEncoding)}: {fStringEncoding}");
            }

            aBytes = 0;// No addional Read
            return(new StringDataType(
                       aHeader,
                       (StringPadding)fStringPadding,
                       (StringEncoding)fStringEncoding));
        }
Esempio n. 6
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));
        }
Esempio n. 7
0
        internal static Datatype Read(
            Hdf5Reader aReader,
            long?aLocalMessageSize,
            out long aBytes)
        {
            if (aLocalMessageSize.HasValue && aLocalMessageSize.Value < DatatypeHeader.HeaderSize)
            {
                throw new ArgumentException("Specified Local Message Size not long enough");
            }
            DatatypeHeader
                fHeader = DatatypeHeader.Read(aReader);
            Datatype
                fMessage;
            long
                fAdditionalBytes;

            long?
                fBodySize = aLocalMessageSize.HasValue
                    ? (long?)aLocalMessageSize.Value - DatatypeHeader.HeaderSize
                    : null;

            switch (fHeader.Class)
            {
            case DatatypeClass.FixedPoint:
                fMessage = FixedPointDataType.ReadMessage(
                    fHeader,
                    aReader,
                    fBodySize,
                    out fAdditionalBytes);
                break;

            case DatatypeClass.FloatingPoint:
                fMessage = FloatingPointDataType.ReadMessage(
                    fHeader,
                    aReader,
                    fBodySize,
                    out fAdditionalBytes);
                break;

            case DatatypeClass.Time:
                fMessage = TimeDataType.ReadMessage(
                    fHeader,
                    aReader,
                    fBodySize,
                    out fAdditionalBytes);
                break;

            case DatatypeClass.String:
                fMessage = StringDataType.ReadMessage(
                    fHeader,
                    aReader,
                    fBodySize,
                    out fAdditionalBytes);
                break;

            case DatatypeClass.BitField:
                fMessage = BitFieldDataType.ReadMessage(
                    fHeader,
                    aReader,
                    fBodySize,
                    out fAdditionalBytes);
                break;

            case DatatypeClass.Opaque:
                fMessage = OpaqueDataType.ReadMessage(
                    fHeader,
                    aReader,
                    fBodySize,
                    out fAdditionalBytes);
                break;



            case DatatypeClass.Array:
                fMessage = ArrayDataType.ReadMessage(
                    fHeader,
                    aReader,
                    fBodySize,
                    out fAdditionalBytes);
                break;

            default:
                // We shoudl never git her, as header parsing should check
                // for known versions of the header
                throw new Exception("Unexpected Version Type");
            }
            aBytes = DatatypeHeader.HeaderSize + fAdditionalBytes;
            return(fMessage);
        }
Esempio n. 8
0
        internal static Datatype ReadMessage(
            DatatypeHeader aHeader,
            Hdf5Reader aReader,
            long?aLocalMessageSize,
            out long aBytes)
        {
            if (aHeader.Class != DatatypeClass.FloatingPoint)
            {
                throw new ArgumentException(
                          $"aHeader must be for type {nameof(DatatypeClass.FloatingPoint)}");
            }

            if (aLocalMessageSize.HasValue && aLocalMessageSize < mcAddionalSize)
            {
                throw new ArgumentException("Specified Local Message Size not long enough");
            }

            Flags fFlags = (Flags)aHeader.Flags;

            ByteOrdering
                fByteOrdering;
            Flags
                fByteOrderFlags = Flags.ByteOrderMask & fFlags;

            switch (fByteOrderFlags)
            {
            case Flags.None:
                fByteOrdering = ByteOrdering.LittleEndian;
                break;

            case Flags.ByteOrderLow:
                fByteOrdering = ByteOrdering.BigEndian;
                break;

            case Flags.ByteOrderMask:
                fByteOrdering = ByteOrdering.VAXOrder;
                break;

            default:
                throw new System.IO.InvalidDataException("Unknown Byte Ordering");
            }

            byte
                fLowPad      = (byte)(fFlags.HasFlag(Flags.LowPad) ? 1 : 0),
                fHighPad     = (byte)(fFlags.HasFlag(Flags.HighPad) ? 1 : 0),
                fInternalPad = (byte)(fFlags.HasFlag(Flags.InternalPad) ? 1 : 0);


            MantissaNormalization
                fMantissaNormalization;
            byte
                fMantissaNormFlags = (byte)((byte)(Flags.MantissaNormalizationMask & fFlags) >> 4);

            if (fMantissaNormFlags > (byte)MantissaNormalization.MsbSetNotStorred)
            {
                throw new System.IO.InvalidDataException("Unknown Mantissa Normalization");
            }
            fMantissaNormalization = (MantissaNormalization)fMantissaNormFlags;

            ushort
                fSignLocation = (ushort)((0x00FF00 & aHeader.Flags) >> 8);

            ushort
                fBitOffset    = aReader.ReadUInt16(),
                fBitPrecision = aReader.ReadUInt16();
            byte
                fExponentLocation = aReader.ReadByte(),
                fExponentSize     = aReader.ReadByte(),
                fMantissaLocation = aReader.ReadByte(),
                fMantissaSize     = aReader.ReadByte();
            uint
                fExponentBias = aReader.ReadUInt32();

            aBytes = mcAddionalSize;
            return(new FloatingPointDataType(
                       aHeader,
                       fByteOrdering,
                       fHighPad,
                       fLowPad,
                       fInternalPad,
                       fSignLocation,
                       fBitOffset,
                       fBitPrecision,
                       fExponentLocation,
                       fExponentSize,
                       fMantissaLocation,
                       fMantissaSize,
                       fExponentBias));
        }