コード例 #1
0
ファイル: ObjectHeader.cs プロジェクト: Apollo3zehn/HDF5.NET
        public ObjectHeader(H5Context context) : base(context.Reader)
        {
            _context = context;

            this.Address        = (ulong)context.Reader.BaseStream.Position;
            this.HeaderMessages = new List <HeaderMessage>();
        }
コード例 #2
0
        internal ObjectHeader1(H5Context context, byte version) : base(context.Reader)
        {
            // version
            this.Version = version;

            // reserved
            context.Reader.ReadByte();

            // header messages count
            this.HeaderMessagesCount = context.Reader.ReadUInt16();

            // object reference count
            this.ObjectReferenceCount = context.Reader.ReadUInt32();

            // object header size
            this.ObjectHeaderSize = context.Reader.ReadUInt32();

            // header messages

            // read padding bytes that align the following message to an 8 byte boundary
            if (this.ObjectHeaderSize > 0)
            {
                context.Reader.ReadBytes(4);
            }

            var messages = this.ReadHeaderMessages(context, this.ObjectHeaderSize, 1);

            this.HeaderMessages.AddRange(messages);
        }
コード例 #3
0
 private H5File(H5Context context,
                NamedReference reference,
                ObjectHeader header,
                string absoluteFilePath,
                bool deleteOnClose)
     : base(context, reference, header)
 {
     this.Path      = absoluteFilePath;
     _deleteOnClose = deleteOnClose;
 }
コード例 #4
0
        internal ObjectHeaderContinuationBlock2(H5Context context, ulong objectHeaderSize, byte version, bool withCreationOrder)
            : base(context.Reader)
        {
            // signature
            var signature = context.Reader.ReadBytes(4);

            H5Utils.ValidateSignature(signature, ObjectHeaderContinuationBlock2.Signature);

            // header messages
            var messages = this.ReadHeaderMessages(context, objectHeaderSize - 8, version, withCreationOrder);

            this.HeaderMessages.AddRange(messages);

#warning H5OCache.c (L. 1595)  /* Gaps should only occur in chunks with no null messages */
#warning read gap and checksum
        }
コード例 #5
0
        internal static ObjectHeader Construct(H5Context context)
        {
            // get version
            var version = context.Reader.ReadByte();

            // must be a version 2+ object header
            if (version != 1)
            {
                var signature = new byte[] { version }.Concat(context.Reader.ReadBytes(3)).ToArray();
                H5Utils.ValidateSignature(signature, ObjectHeader2.Signature);
                version = context.Reader.ReadByte();
            }

            return(version switch
            {
                1 => new ObjectHeader1(context, version),
                2 => new ObjectHeader2(context, version),
                _ => throw new NotSupportedException($"The object header version '{version}' is not supported.")
            });
コード例 #6
0
        internal static FractalHeapId Construct(H5Context context, H5BinaryReader localReader, FractalHeapHeader header)
        {
            var firstByte = localReader.ReadByte();

            // bits 6-7
            var version = (byte)((firstByte & 0xB0) >> 6);

            if (version != 0)
            {
                throw new FormatException($"Only version 0 instances of type {nameof(FractalHeapId)} are supported.");
            }

            // bits 4-5
            var type = (FractalHeapIdType)((firstByte & 0x30) >> 4);

            // offset and length Size (for managed objects fractal heap id)
            var offsetSize = (ulong)Math.Ceiling(header.MaximumHeapSize / 8.0);

#warning Is -1 correct?
            var lengthSize = H5Utils.FindMinByteCount(header.MaximumDirectBlockSize - 1);

            // H5HF.c (H5HF_op)
            return((FractalHeapId)((type, header.HugeIdsAreDirect, header.IOFilterEncodedLength, header.TinyObjectsAreExtended) switch
            {
                (FractalHeapIdType.Managed, _, _, _) => new ManagedObjectsFractalHeapId(context.Reader, localReader, header, offsetSize, lengthSize),

                // H5HFhuge.c (H5HF__huge_op_real)
                (FractalHeapIdType.Huge, false, 0, _) => new HugeObjectsFractalHeapIdSubType1(context.Reader, context.Superblock, localReader, header),
                (FractalHeapIdType.Huge, false, _, _) => new HugeObjectsFractalHeapIdSubType2(context.Reader, context.Superblock, localReader, header),
                (FractalHeapIdType.Huge, true, 0, _) => new HugeObjectsFractalHeapIdSubType3(context.Reader, context.Superblock, localReader),
                (FractalHeapIdType.Huge, true, _, _) => new HugeObjectsFractalHeapIdSubType4(context.Reader, context.Superblock, localReader),

                // H5HFtiny.c (H5HF_tiny_op_real)
                (FractalHeapIdType.Tiny, _, _, false) => new TinyObjectsFractalHeapIdSubType1(localReader, firstByte),
                (FractalHeapIdType.Tiny, _, _, true) => new TinyObjectsFractalHeapIdSubType2(localReader, firstByte),

                // default
                _ => throw new Exception($"Unknown heap ID type '{type}'.")
            }));
コード例 #7
0
        internal ObjectHeader2(H5Context context, byte version) : base(context.Reader)
        {
            // version
            this.Version = version;

            // flags
            this.Flags = (ObjectHeaderFlags)context.Reader.ReadByte();

            // access time, modification time, change time and birth time
            if (this.Flags.HasFlag(ObjectHeaderFlags.StoreFileAccessTimes))
            {
                this.AccessTime       = context.Reader.ReadUInt32();
                this.ModificationTime = context.Reader.ReadUInt32();
                this.ChangeTime       = context.Reader.ReadUInt32();
                this.BirthTime        = context.Reader.ReadUInt32();
            }

            // maximum compact attributes count and minimum dense attributes count
            if (this.Flags.HasFlag(ObjectHeaderFlags.StoreNonDefaultAttributePhaseChangeValues))
            {
                this.MaximumCompactAttributesCount = context.Reader.ReadUInt16();
                this.MinimumDenseAttributesCount   = context.Reader.ReadUInt16();
            }

            // size of chunk 0
            var chunkFieldSize = (byte)(1 << ((byte)this.Flags & 0x03));

            this.SizeOfChunk0 = H5Utils.ReadUlong(this.Reader, chunkFieldSize);

            // header messages
            var withCreationOrder = this.Flags.HasFlag(ObjectHeaderFlags.TrackAttributeCreationOrder);
            var messages          = this.ReadHeaderMessages(context, this.SizeOfChunk0, version: 2, withCreationOrder);

            this.HeaderMessages.AddRange(messages);

#warning H5OCache.c (L. 1595)  /* Gaps should only occur in chunks with no null messages */
#warning read gap and checksum
        }
コード例 #8
0
 internal H5Group(H5File file, H5Context context, H5NamedReference reference, ObjectHeader header)
     : base(context, reference, header)
 {
     _file = file;
 }
コード例 #9
0
 internal H5Group(H5File file, H5Context context, H5NamedReference reference)
     : base(context, reference)
 {
     _file       = file;
     _scratchPad = reference.ScratchPad;
 }
コード例 #10
0
 // Only for H5File constructor
 internal H5Group(H5Context context, H5NamedReference reference, ObjectHeader header)
     : base(context, reference, header)
 {
     //
 }
コード例 #11
0
        internal HeaderMessage(H5Context context, byte version, bool withCreationOrder = false) : base(context.Reader)
        {
            this.Version           = version;
            this.WithCreationOrder = withCreationOrder;

            // version
            if (version == 1)
            {
                this.Type = (HeaderMessageType)context.Reader.ReadUInt16();
            }
            else if (version == 2)
            {
                this.Type = (HeaderMessageType)context.Reader.ReadByte();
            }

            // data size
            this.DataSize = context.Reader.ReadUInt16();

            // flags
            this.Flags = (HeaderMessageFlags)context.Reader.ReadByte();

            // reserved / creation order
            if (version == 1)
            {
                context.Reader.ReadBytes(3);
            }
            else if (version == 2 && withCreationOrder)
            {
                this.CreationOrder = context.Reader.ReadUInt16();
            }

            // data
            var readerPosition1 = context.Reader.BaseStream.Position;

            this.Data = this.Type switch
            {
                HeaderMessageType.NIL => new NilMessage(context.Reader),
                HeaderMessageType.Dataspace => new DataspaceMessage(context.Reader, context.Superblock),
                HeaderMessageType.LinkInfo => new LinkInfoMessage(context.Reader, context.Superblock),
                HeaderMessageType.Datatype => new DatatypeMessage(context.Reader),
                HeaderMessageType.OldFillValue => new OldFillValueMessage(context.Reader),
                HeaderMessageType.FillValue => new FillValueMessage(context.Reader),
                HeaderMessageType.Link => new LinkMessage(context.Reader, context.Superblock),
                HeaderMessageType.ExternalDataFiles => new ExternalFileListMessage(context.Reader, context.Superblock),
                HeaderMessageType.DataLayout => DataLayoutMessage.Construct(context.Reader, context.Superblock),
                HeaderMessageType.Bogus => new BogusMessage(context.Reader),
                HeaderMessageType.GroupInfo => new GroupInfoMessage(context.Reader),
                HeaderMessageType.FilterPipeline => new FilterPipelineMessage(context.Reader),
                HeaderMessageType.Attribute => new AttributeMessage(context.Reader, context.Superblock),
                HeaderMessageType.ObjectComment => new ObjectCommentMessage(context.Reader),
                HeaderMessageType.OldObjectModificationTime => new OldObjectModificationTimeMessage(context.Reader),
                HeaderMessageType.SharedMessageTable => new SharedMessageTableMessage(context.Reader, context.Superblock),
                HeaderMessageType.ObjectHeaderContinuation => new ObjectHeaderContinuationMessage(context.Reader, context.Superblock),
                HeaderMessageType.SymbolTable => new SymbolTableMessage(context.Reader, context.Superblock),
                HeaderMessageType.ObjectModification => new ObjectModificationMessage(context.Reader),
                HeaderMessageType.BTreeKValues => new BTreeKValuesMessage(context.Reader),
                HeaderMessageType.DriverInfo => new DriverInfoMessage(context.Reader),
                HeaderMessageType.AttributeInfo => new AttributeInfoMessage(context.Reader, context.Superblock),
                HeaderMessageType.ObjectReferenceCount => new ObjectReferenceCountMessage(context.Reader),
                _ => throw new NotSupportedException($"The message type '{this.Type}' is not supported.")
            };

            var readerPosition2 = context.Reader.BaseStream.Position;
            var paddingBytes    = this.DataSize - (readerPosition2 - readerPosition1);

            context.Reader.ReadBytes((int)paddingBytes);
        }
コード例 #12
0
 internal H5Object(H5Context context, H5NamedReference reference)
 {
     this.Context   = context;
     this.Reference = reference;
 }
コード例 #13
0
 internal H5AttributableObject(H5Context context, H5NamedReference reference)
     : base(context, reference)
 {
     //
 }
コード例 #14
0
 internal H5AttributableObject(H5Context context, H5NamedReference reference, ObjectHeader header)
     : base(context, reference, header)
 {
     //
 }
コード例 #15
0
 internal H5Object(H5Context context, H5NamedReference reference, ObjectHeader header)
 {
     this.Context   = context;
     this.Reference = reference;
     _header        = header;
 }
コード例 #16
0
        internal H5Dataset(H5Context context, H5NamedReference reference, ObjectHeader header)
            : base(context, reference, header)
        {
            foreach (var message in this.Header.HeaderMessages)
            {
                var type = message.Data.GetType();

                if (typeof(DataLayoutMessage).IsAssignableFrom(type))
                {
                    this.DataLayout = (DataLayoutMessage)message.Data;
                }

                else if (type == typeof(DataspaceMessage))
                {
                    this.Dataspace = (DataspaceMessage)message.Data;
                }

                else if (type == typeof(DatatypeMessage))
                {
                    this.Datatype = (DatatypeMessage)message.Data;
                }

                else if (type == typeof(FillValueMessage))
                {
                    this.FillValue = (FillValueMessage)message.Data;
                }

                else if (type == typeof(FilterPipelineMessage))
                {
                    this.FilterPipeline = (FilterPipelineMessage)message.Data;
                }

                else if (type == typeof(ObjectModificationMessage))
                {
                    this.ObjectModification = (ObjectModificationMessage)message.Data;
                }

                else if (type == typeof(ExternalFileListMessage))
                {
                    this.ExternalFileList = (ExternalFileListMessage)message.Data;
                }
            }

            // check that required fields are set
            if (this.DataLayout == null)
            {
                throw new Exception("The data layout message is missing.");
            }

            if (this.Dataspace == null)
            {
                throw new Exception("The dataspace message is missing.");
            }

            if (this.Datatype == null)
            {
                throw new Exception("The data type message is missing.");
            }

            if (this.FillValue == null)
            {
                throw new Exception("The fill value message is missing.");
            }
        }
コード例 #17
0
 internal H5CommitedDatatype(H5Context context, ObjectHeader header, NamedReference reference)
     : base(context, reference, header)
 {
     this.Datatype = header.GetMessage <DatatypeMessage>();
 }
コード例 #18
0
        public AttributeMessage(H5Context context, ObjectHeader objectHeader) : base(context.Reader)
        {
            _context = context;

            // version
            this.Version = context.Reader.ReadByte();

            if (this.Version == 1)
            {
                context.Reader.ReadByte();
            }
            else
            {
                this.Flags = (AttributeMessageFlags)context.Reader.ReadByte();
            }

            // name size
            var nameSize = context.Reader.ReadUInt16();

            // datatype size
            var datatypeSize = context.Reader.ReadUInt16();

            // dataspace size
            var dataspaceSize = context.Reader.ReadUInt16();

            // name character set encoding
            if (this.Version == 3)
            {
                _nameEncoding = (CharacterSetEncoding)context.Reader.ReadByte();
            }

            // name
            if (this.Version == 1)
            {
                this.Name = H5Utils.ReadNullTerminatedString(context.Reader, pad: true, encoding: _nameEncoding);
            }
            else
            {
                this.Name = H5Utils.ReadNullTerminatedString(context.Reader, pad: false, encoding: _nameEncoding);
            }

            // datatype
            var flags1 = this.Flags.HasFlag(AttributeMessageFlags.SharedDatatype)
                ? MessageFlags.Shared
                : MessageFlags.NoFlags;

            this.Datatype = objectHeader.DecodeMessage(flags1,
                                                       () => new DatatypeMessage(context.Reader));

            if (this.Version == 1)
            {
                var paddedSize    = (int)(Math.Ceiling(datatypeSize / 8.0) * 8);
                var remainingSize = paddedSize - datatypeSize;
                context.Reader.ReadBytes(remainingSize);
            }

            // dataspace
            var flags2 = this.Flags.HasFlag(AttributeMessageFlags.SharedDataspace)
                ? MessageFlags.Shared
                : MessageFlags.NoFlags;

            this.Dataspace = objectHeader.DecodeMessage(flags2,
                                                        () => new DataspaceMessage(context.Reader, context.Superblock));

            if (this.Version == 1)
            {
                var paddedSize    = (int)(Math.Ceiling(dataspaceSize / 8.0) * 8);
                var remainingSize = paddedSize - dataspaceSize;
                this.Reader.Seek(remainingSize, SeekOrigin.Current);
            }

            // data
            var byteSize = H5Utils.CalculateSize(this.Dataspace.DimensionSizes, this.Dataspace.Type) * this.Datatype.Size;

            this.Data = context.Reader.ReadBytes((int)byteSize);
        }