Example #1
0
        public BTree1Node(H5BinaryReader reader, Superblock superblock, Func <T> decodeKey)
        {
            _reader     = reader;
            _superblock = superblock;
            _decodeKey  = decodeKey;

            var signature = reader.ReadBytes(4);

            H5Utils.ValidateSignature(signature, BTree1Node <T> .Signature);

            this.NodeType    = (BTree1NodeType)reader.ReadByte();
            this.NodeLevel   = reader.ReadByte();
            this.EntriesUsed = reader.ReadUInt16();

            this.LeftSiblingAddress  = superblock.ReadOffset(reader);
            this.RightSiblingAddress = superblock.ReadOffset(reader);

            this.Keys           = new T[this.EntriesUsed + 1];
            this.ChildAddresses = new ulong[this.EntriesUsed];

            for (int i = 0; i < this.EntriesUsed; i++)
            {
                this.Keys[i]           = decodeKey();
                this.ChildAddresses[i] = superblock.ReadOffset(reader);
            }

            this.Keys[this.EntriesUsed] = decodeKey();
        }
        public MultiDriverInfo(H5BinaryReader reader) : base(reader)
        {
            // member mapping
            this.MemberMapping1 = (MemberMapping)reader.ReadByte();
            this.MemberMapping2 = (MemberMapping)reader.ReadByte();
            this.MemberMapping3 = (MemberMapping)reader.ReadByte();
            this.MemberMapping4 = (MemberMapping)reader.ReadByte();
            this.MemberMapping5 = (MemberMapping)reader.ReadByte();
            this.MemberMapping6 = (MemberMapping)reader.ReadByte();

            // reserved
            reader.ReadBytes(3);

            // member count
            var memberCount = new MemberMapping[] { this.MemberMapping1, this.MemberMapping2, this.MemberMapping3,
                                                    this.MemberMapping4, this.MemberMapping5, this.MemberMapping6 }.Distinct().Count();

            // member start and end addresses
            this.MemberFileStartAddresses = new List <ulong>(memberCount);
            this.MemberFileEndAddresses   = new List <ulong>(memberCount);

            for (int i = 0; i < memberCount; i++)
            {
                this.MemberFileStartAddresses[i] = reader.ReadUInt64();
                this.MemberFileEndAddresses[i]   = reader.ReadUInt64();
            }

            // member names
            this.MemberNames = new List <string>(memberCount);

            for (int i = 0; i < memberCount; i++)
            {
                this.MemberNames[i] = H5Utils.ReadNullTerminatedString(reader, pad: true);
            }
        }
        public BTree2Node(H5BinaryReader reader, BTree2Header <T> header, ushort recordCount, byte[] signature, Func <T> decodeKey)
            : base(reader)
        {
            // signature
            var actualSignature = reader.ReadBytes(4);

            H5Utils.ValidateSignature(actualSignature, signature);

            // version
            this.Version = reader.ReadByte();

            // type
            this.Type = (BTree2Type)reader.ReadByte();

            if (this.Type != header.Type)
            {
                throw new FormatException($"The BTree2 internal node type ('{this.Type}') does not match the type defined in the header ('{header.Type}').");
            }

            // records
            this.Records = new T[recordCount];

            for (ulong i = 0; i < recordCount; i++)
            {
                this.Records[i] = decodeKey();
            }
        }
Example #4
0
        public FixedArrayHeader(H5BinaryReader reader, Superblock superblock, uint chunkSizeLength) : base(reader)
        {
            _superblock      = superblock;
            _chunkSizeLength = chunkSizeLength;

            // signature
            var signature = reader.ReadBytes(4);

            H5Utils.ValidateSignature(signature, FixedArrayHeader.Signature);

            // version
            this.Version = reader.ReadByte();

            // client ID
            this.ClientID = (ClientID)reader.ReadByte();

            // entry size
            this.EntrySize = reader.ReadByte();

            // page bits
            this.PageBits = reader.ReadByte();

            // entries count
            this.EntriesCount = superblock.ReadLength(reader);

            // data block address
            this.DataBlockAddress = superblock.ReadOffset(reader);

            // checksum
            this.Checksum = reader.ReadUInt32();
        }
Example #5
0
        public FractalHeapDirectBlock(FractalHeapHeader header, H5BinaryReader reader, Superblock superblock) : base(reader)
        {
            _superblock = superblock;
            var headerSize = 0UL;

            // signature
            var signature = reader.ReadBytes(4);

            headerSize += 4;
            H5Utils.ValidateSignature(signature, FractalHeapDirectBlock.Signature);

            // version
            this.Version = reader.ReadByte();
            headerSize  += 1;

            // heap header address
            this.HeapHeaderAddress = superblock.ReadOffset(reader);
            headerSize            += superblock.OffsetsSize;

            // block offset
            var blockOffsetFieldSize = (int)Math.Ceiling(header.MaximumHeapSize / 8.0);

            this.BlockOffset = H5Utils.ReadUlong(this.Reader, (ulong)blockOffsetFieldSize);
            headerSize      += (ulong)blockOffsetFieldSize;

            // checksum
            if (header.Flags.HasFlag(FractalHeapHeaderFlags.DirectBlocksAreChecksummed))
            {
                this.Checksum = reader.ReadUInt32();
                headerSize   += 4;
            }

            this.HeaderSize = headerSize;
        }
Example #6
0
        public GlobalHeapCollection(H5BinaryReader reader, Superblock superblock) : base(reader)
        {
            // signature
            var signature = reader.ReadBytes(4);

            H5Utils.ValidateSignature(signature, GlobalHeapCollection.Signature);

            // version
            this.Version = reader.ReadByte();

            // reserved
            reader.ReadBytes(3);

            // collection size
            this.CollectionSize = superblock.ReadLength(reader);

            // global heap objects
            this.GlobalHeapObjects = new List <GlobalHeapObject>();

            var headerSize = 8UL + superblock.LengthsSize;
            var remaining  = this.CollectionSize;

            while (remaining > headerSize)
            {
                var before           = reader.BaseStream.Position;
                var globalHeapObject = new GlobalHeapObject(reader, superblock);
                this.GlobalHeapObjects.Add(globalHeapObject);
                var after    = reader.BaseStream.Position;
                var consumed = (ulong)(after - before);

                remaining -= consumed;
            }
        }
Example #7
0
        public EnumerationPropertyDescription(H5BinaryReader reader, byte version, uint valueSize, ushort memberCount) : base(reader)
        {
            // base type
            this.BaseType = new DatatypeMessage(reader);

            // names
            this.Names = new List <string>(memberCount);

            for (int i = 0; i < memberCount; i++)
            {
                if (version <= 2)
                {
                    this.Names.Add(H5Utils.ReadNullTerminatedString(reader, pad: true));
                }
                else
                {
                    this.Names.Add(H5Utils.ReadNullTerminatedString(reader, pad: false));
                }
            }

            // values
            this.Values = new List <byte[]>(memberCount);

            for (int i = 0; i < memberCount; i++)
            {
                this.Values.Add(reader.ReadBytes((int)valueSize));
            }
        }
Example #8
0
        public BTree2InternalNode(H5BinaryReader reader, Superblock superblock, BTree2Header <T> header, ushort recordCount, int nodeLevel, Func <T> decodeKey)
            : base(reader, header, recordCount, BTree2InternalNode <T> .Signature, decodeKey)
        {
            this.NodePointers = new BTree2NodePointer[recordCount + 1];

            // H5B2cache.c (H5B2__cache_int_deserialize)
            for (int i = 0; i < recordCount + 1; i++)
            {
                // address
                this.NodePointers[i].Address = superblock.ReadOffset(reader);

                // record count
                var childRecordCount = H5Utils.ReadUlong(reader, header.MaxRecordCountSize);
                this.NodePointers[i].RecordCount = (ushort)childRecordCount;

                // total record count
                if (nodeLevel > 1)
                {
                    var totalChildRecordCount = H5Utils.ReadUlong(reader, header.NodeInfos[nodeLevel - 1].CumulatedTotalRecordCountSize);
                    this.NodePointers[i].TotalRecordCount = totalChildRecordCount;
                }
                else
                {
                    this.NodePointers[i].TotalRecordCount = childRecordCount;
                }
            }

            // checksum
            this.Checksum = reader.ReadUInt32();
        }
Example #9
0
        public T[] Read <T>() where T : struct
        {
            switch (this.Message.Datatype.Class)
            {
            case DatatypeMessageClass.FixedPoint:
            case DatatypeMessageClass.FloatingPoint:
            case DatatypeMessageClass.BitField:
            case DatatypeMessageClass.Opaque:
            case DatatypeMessageClass.Compound:
            case DatatypeMessageClass.Reference:
            case DatatypeMessageClass.Enumerated:
            case DatatypeMessageClass.Array:
                break;

            default:
                throw new Exception($"This method can only be used with one of the following type classes: '{DatatypeMessageClass.FixedPoint}', '{DatatypeMessageClass.FloatingPoint}', '{DatatypeMessageClass.BitField}', '{DatatypeMessageClass.Opaque}', '{DatatypeMessageClass.Compound}', '{DatatypeMessageClass.Reference}', '{DatatypeMessageClass.Enumerated}' and '{DatatypeMessageClass.Array}'.");
            }

            var buffer         = this.Message.Data;
            var byteOrderAware = this.Message.Datatype.BitField as IByteOrderAware;

            if (byteOrderAware != null)
            {
                H5Utils.EnsureEndianness(buffer.ToArray(), buffer, byteOrderAware.ByteOrder, this.Message.Datatype.Size);
            }

            return(MemoryMarshal
                   .Cast <byte, T>(this.Message.Data)
                   .ToArray());
        }
Example #10
0
        public T[] ReadCompound <T>(
            Func <FieldInfo, string>?getName = default,
            Selection?fileSelection          = default,
            Selection?memorySelection        = default,
            ulong[]?memoryDims            = default,
            H5DatasetAccess datasetAccess = default) where T : struct
        {
            var data = this.Read <byte>(
                null,
                fileSelection,
                memorySelection,
                memoryDims,
                datasetAccess,
                skipShuffle: false);

            if (data is null)
            {
                throw new Exception("The buffer is null. This should never happen.");
            }

            if (getName is null)
            {
                getName = fieldInfo => fieldInfo.Name;
            }

            return(H5Utils.ReadCompound <T>(this.InternalDataType, this.InternalDataspace, this.Context.Superblock, data, getName));
        }
        public override void Initialize()
        {
            base.Initialize();

            _unlimitedDim = this.Dataset.InternalDataspace.DimensionMaxSizes
                            .ToList()
                            .FindLastIndex(value => value == H5Constants.Unlimited);

            // H5Dearray.c (H5D__earray_idx_resize)

            /* "Swizzle" constant dimensions for this dataset */
            if (_unlimitedDim > 0)
            {
                /* Get the swizzled chunk dimensions */
                _swizzledChunkDims = this.ChunkDims.ToArray();
                H5Utils.SwizzleCoords(_swizzledChunkDims, _unlimitedDim);

                /* Get the swizzled number of chunks in each dimension */
                var swizzledScaledDims = this.ScaledDims.ToArray();
                H5Utils.SwizzleCoords(swizzledScaledDims, _unlimitedDim);

                /* Get the swizzled "down" sizes for each dimension */
                _swizzledDownChunkCounts = swizzledScaledDims.AccumulateReverse();

                /* Get the swizzled max number of chunks in each dimension */
                var swizzledScaledMaxDims = this.ScaledMaxDims.ToArray();
                H5Utils.SwizzleCoords(swizzledScaledMaxDims, _unlimitedDim);

                /* Get the swizzled max "down" sizes for each dimension */
                _swizzledDownMaxChunkCounts = swizzledScaledMaxDims.AccumulateReverse();
            }
        }
Example #12
0
        public ManagedObjectsFractalHeapId(H5BinaryReader reader, H5BinaryReader localReader, FractalHeapHeader header, ulong offsetByteCount, ulong lengthByteCount)
        {
            _reader = reader;
            _header = header;

            this.Offset = H5Utils.ReadUlong(localReader, offsetByteCount);
            this.Length = H5Utils.ReadUlong(localReader, lengthByteCount);
        }
Example #13
0
        public FractalHeapIndirectBlock(FractalHeapHeader header, H5BinaryReader reader, Superblock superblock, uint rowCount) : base(reader)
        {
            _superblock   = superblock;
            this.RowCount = rowCount;

            // signature
            var signature = reader.ReadBytes(4);

            H5Utils.ValidateSignature(signature, FractalHeapIndirectBlock.Signature);

            // version
            this.Version = reader.ReadByte();

            // heap header address
            this.HeapHeaderAddress = superblock.ReadOffset(reader);

            // block offset
            var blockOffsetFieldSize = (int)Math.Ceiling(header.MaximumHeapSize / 8.0);

            this.BlockOffset = H5Utils.ReadUlong(this.Reader, (ulong)blockOffsetFieldSize);

            // H5HFcache.c (H5HF__cache_iblock_deserialize)
            var length = rowCount * header.TableWidth;

            this.Entries = new FractalHeapEntry[length];

            for (uint i = 0; i < this.Entries.Length; i++)
            {
                /* Decode child block address */
                this.Entries[i].Address = _superblock.ReadOffset(reader);

                /* Check for heap with I/O filters */
                if (header.IOFilterEncodedLength > 0)
                {
                    /* Decode extra information for direct blocks */
                    if (i < (header.MaxDirectRows * header.TableWidth))
                    {
                        /* Size of filtered direct block */
                        this.Entries[i].FilteredSize = _superblock.ReadLength(reader);

                        /* I/O filter mask for filtered direct block */
                        this.Entries[i].FilterMask = reader.ReadUInt32();
                    }
                }


                /* Count child blocks */
                if (!superblock.IsUndefinedAddress(this.Entries[i].Address))
                {
                    this.ChildCount++;
                    this.MaxChildIndex = i;
                }
            }

            // checksum
            this.Checksum = reader.ReadUInt32();
        }
Example #14
0
        internal HugeObjectsFractalHeapIdSubType1(H5BinaryReader reader, Superblock superblock, H5BinaryReader localReader, FractalHeapHeader header)
        {
            _reader     = reader;
            _superblock = superblock;
            _heapHeader = header;

            // BTree2 key
            this.BTree2Key = H5Utils.ReadUlong(localReader, header.HugeIdsSize);
        }
Example #15
0
        public FreeSpaceManagerHeader(H5BinaryReader reader, Superblock superblock) : base(reader)
        {
            // signature
            var signature = reader.ReadBytes(4);

            H5Utils.ValidateSignature(signature, FreeSpaceManagerHeader.Signature);

            // version
            this.Version = reader.ReadByte();

            // client ID
            this.ClientId = (ClientId)reader.ReadByte();

            // total space tracked
            this.TotalSpaceTracked = superblock.ReadLength(reader);

            // total sections count
            this.TotalSectionsCount = superblock.ReadLength(reader);

            // serialized sections count
            this.SerializedSectionsCount = superblock.ReadLength(reader);

            // un-serialized sections count
            this.UnSerializedSectionsCount = superblock.ReadLength(reader);

            // section classes count
            this.SectionClassesCount = reader.ReadUInt16();

            // shrink percent
            this.ShrinkPercent = reader.ReadUInt16();

            // expand percent
            this.ExpandPercent = reader.ReadUInt16();

            // address space size
            this.AddressSpaceSize = reader.ReadUInt16();

            // maximum section size
            this.MaximumSectionSize = superblock.ReadLength(reader);

            // serialized section list address
            this.SerializedSectionListAddress = superblock.ReadOffset(reader);

            // serialized section list used
            this.SerializedSectionListUsed = superblock.ReadLength(reader);

            // serialized section list allocated size
            this.SerializedSectionListAllocatedSize = superblock.ReadLength(reader);

            // checksum
            this.Checksum = reader.ReadUInt32();
        }
        public SharedObjectHeaderMessageTable(H5BinaryReader reader) : base(reader)
        {
            // signature
            var signature = reader.ReadBytes(4);

            H5Utils.ValidateSignature(signature, SharedObjectHeaderMessageTable.Signature);

            //
#warning implement this correctly

            // checksum
            this.Checksum = reader.ReadUInt32();
        }
Example #17
0
        protected override ChunkInfo GetChunkInfo(ulong[] chunkIndices)
        {
            if (this.Dataset.InternalFilterPipeline is null)
            {
                if (_btree2_no_filter is null)
                {
                    this.Dataset.Context.Reader.Seek((long)this.Dataset.InternalDataLayout.Address, SeekOrigin.Begin);

                    Func <BTree2Record10> decodeKey
                        = () => this.DecodeRecord10(this.ChunkRank);

                    _btree2_no_filter = new BTree2Header <BTree2Record10>(this.Dataset.Context.Reader, this.Dataset.Context.Superblock, decodeKey);
                }

                // get record
                var success = _btree2_no_filter.TryFindRecord(out var record, record =>
                {
                    // H5Dbtree2.c (H5D__bt2_compare)
                    return(H5Utils.VectorCompare(this.ChunkRank, chunkIndices, record.ScaledOffsets));
                });

                return(success
                    ? new ChunkInfo(record.Address, this.ChunkByteSize, 0)
                    : ChunkInfo.None);
            }
            else
            {
                if (_btree2_filter is null)
                {
                    this.Dataset.Context.Reader.Seek((long)this.Dataset.InternalDataLayout.Address, SeekOrigin.Begin);
                    var chunkSizeLength = H5Utils.ComputeChunkSizeLength(this.ChunkByteSize);

                    Func <BTree2Record11> decodeKey =
                        () => this.DecodeRecord11(this.ChunkRank, chunkSizeLength);

                    _btree2_filter = new BTree2Header <BTree2Record11>(this.Dataset.Context.Reader, this.Dataset.Context.Superblock, decodeKey);
                }

                // get record
                var success = _btree2_filter.TryFindRecord(out var record, record =>
                {
                    // H5Dbtree2.c (H5D__bt2_compare)
                    return(H5Utils.VectorCompare(this.ChunkRank, chunkIndices, record.ScaledOffsets));
                });

                return(success
                    ? new ChunkInfo(record.Address, record.ChunkSize, record.FilterMask)
                    : ChunkInfo.None);
            }
        }
Example #18
0
        public ExtensibleArrayIndexBlock(
            H5BinaryReader reader,
            Superblock superblock,
            ExtensibleArrayHeader header,
            Func <H5BinaryReader, T> decode)
        {
            // H5EAiblock.c (H5EA__iblock_alloc)
            this.SecondaryBlockDataBlockAddressCount = 2 * (ulong)Math.Log(header.SecondaryBlockMinimumDataBlockPointerCount, 2);
            ulong dataBlockPointerCount      = (ulong)(2 * (header.SecondaryBlockMinimumDataBlockPointerCount - 1));
            ulong secondaryBlockPointerCount = header.SecondaryBlockCount - this.SecondaryBlockDataBlockAddressCount;

            // signature
            var signature = reader.ReadBytes(4);

            H5Utils.ValidateSignature(signature, ExtensibleArrayIndexBlock <T> .Signature);

            // version
            this.Version = reader.ReadByte();

            // client ID
            this.ClientID = (ClientID)reader.ReadByte();

            // header address
            this.HeaderAddress = superblock.ReadOffset(reader);

            // elements
            this.Elements = Enumerable
                            .Range(0, header.IndexBlockElementsCount)
                            .Select(i => decode(reader))
                            .ToArray();

            // data block addresses
            this.DataBlockAddresses = new ulong[dataBlockPointerCount];

            for (ulong i = 0; i < dataBlockPointerCount; i++)
            {
                this.DataBlockAddresses[i] = superblock.ReadOffset(reader);
            }

            // secondary block addresses
            this.SecondaryBlockAddresses = new ulong[secondaryBlockPointerCount];

            for (ulong i = 0; i < secondaryBlockPointerCount; i++)
            {
                this.SecondaryBlockAddresses[i] = superblock.ReadOffset(reader);
            }

            // checksum
            this.Checksum = reader.ReadUInt32();
        }
        public SharedMessageRecordList(H5BinaryReader reader) : base(reader)
        {
            // signature
            var signature = reader.ReadBytes(4);

            H5Utils.ValidateSignature(signature, SharedMessageRecordList.Signature);

            // share message records
            this.SharedMessageRecords = new List <SharedMessageRecord>();
#warning how to know how many?

            // checksum
            this.Checksum = reader.ReadUInt32();
        }
Example #20
0
        private Span <byte> GetBuffer <T>(out T[] result) where T : struct
        {
            // first, get byte size
            var byteSize = H5Utils.CalculateSize(this.Dataspace.DimensionSizes, this.Dataspace.Type) * this.Datatype.Size;

            // second, convert file type (e.g. 2 bytes) to T (e.g. 4 bytes)
            var arraySize = byteSize / (ulong)Unsafe.SizeOf <T>();

            // finally, create buffer
            result = new T[arraySize];
            var buffer = MemoryMarshal.AsBytes(result.AsSpan());

            return(buffer);
        }
Example #21
0
        public LinkMessage(H5BinaryReader reader, Superblock superblock) : base(reader)
        {
            // version
            this.Version = reader.ReadByte();

            // flags
            this.Flags = reader.ReadByte();

            // link type
            var isLinkTypeFieldPresent = (this.Flags & (1 << 3)) > 0;

            if (isLinkTypeFieldPresent)
            {
                this.LinkType = (LinkType)reader.ReadByte();
            }

            // creation order
            var isCreationOrderFieldPresent = (this.Flags & (1 << 2)) > 0;

            if (isCreationOrderFieldPresent)
            {
                this.CreationOrder = reader.ReadUInt64();
            }

            // link name encoding
            var isLinkNameEncodingFieldPresent = (this.Flags & (1 << 4)) > 0;

            if (isLinkNameEncodingFieldPresent)
            {
                this.LinkNameEncoding = (CharacterSetEncoding)reader.ReadByte();
            }

            // link length
            var linkLengthFieldLength = (ulong)(1 << (this.Flags & 0x03));
            var linkNameLength        = H5Utils.ReadUlong(this.Reader, linkLengthFieldLength);

            // link name
            this.LinkName = H5Utils.ReadFixedLengthString(reader, (int)linkNameLength, this.LinkNameEncoding);

            // link info
            this.LinkInfo = this.LinkType switch
            {
                LinkType.Hard => new HardLinkInfo(reader, superblock),
                LinkType.Soft => new SoftLinkInfo(reader),
                LinkType.External => new ExternalLinkInfo(reader),
                _ when(65 <= (byte)this.LinkType && (byte)this.LinkType <= 255) => new UserDefinedLinkInfo(reader),
                _ => throw new NotSupportedException($"The link message link type '{this.LinkType}' is not supported.")
            };
        }
        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
        }
        public FixedArrayDataBlock(H5BinaryReader reader, Superblock superblock, FixedArrayHeader header, uint chunkSizeLength)
        {
            // H5FAdblock.c (H5FA__dblock_alloc)
            this.ElementsPerPage = 1UL << header.PageBits;
            this.PageCount       = 0UL;

            var pageBitmapSize = 0UL;

            if (header.EntriesCount > this.ElementsPerPage)
            {
                /* Compute number of pages */
                this.PageCount = (header.EntriesCount + this.ElementsPerPage - 1) / this.ElementsPerPage;

                /* Compute size of 'page init' flag array, in bytes */
                pageBitmapSize = (this.PageCount + 7) / 8;
            }

            // signature
            var signature = reader.ReadBytes(4);

            H5Utils.ValidateSignature(signature, FixedArrayDataBlock.Signature);

            // version
            this.Version = reader.ReadByte();

            // client ID
            this.ClientID = (ClientID)reader.ReadByte();

            // header address
            this.HeaderAddress = superblock.ReadOffset(reader);

            // page bitmap
            if (this.PageCount > 0)
            {
                this.PageBitmap = reader.ReadBytes((int)pageBitmapSize);
            }

            // elements
            else
            {
                this.Elements = ArrayIndexUtils.ReadElements(reader, superblock, header.EntriesCount, this.ClientID, chunkSizeLength);
            }

            // checksum
            this.Checksum = reader.ReadUInt32();
        }
Example #24
0
        public ExtensibleArrayDataBlock(H5BinaryReader reader, Superblock superblock, ExtensibleArrayHeader header, ulong elementCount, Func <H5BinaryReader, T> decode)
        {
            // H5EAdblock.c (H5EA__dblock_alloc)
            this.PageCount = 0UL;

            if (elementCount > header.DataBlockPageElementsCount)
            {
                /* Set the # of pages in the data block */
                this.PageCount = elementCount / header.DataBlockPageElementsCount;
            }

            // H5EAcache.c (H5EA__cache_dblock_deserialize)

            // signature
            var signature = reader.ReadBytes(4);

            H5Utils.ValidateSignature(signature, ExtensibleArrayDataBlock <T> .Signature);

            // version
            this.Version = reader.ReadByte();

            // client ID
            this.ClientID = (ClientID)reader.ReadByte();

            // header address
            this.HeaderAddress = superblock.ReadOffset(reader);

            // block offset
            this.BlockOffset = H5Utils.ReadUlong(reader, header.ArrayOffsetsSize);

            // elements
            if (this.PageCount == 0)
            {
                this.Elements = Enumerable
                                .Range(0, (int)elementCount)
                                .Select(i => decode(reader))
                                .ToArray();
            }
            else
            {
                this.Elements = new T[0];
            }

            // checksum
            this.Checksum = reader.ReadUInt32();
        }
        public ExternalLinkInfo(H5BinaryReader reader) : base(reader)
        {
            // value length
            this.ValueLength = reader.ReadUInt16();

            // version and flags
            var data = reader.ReadByte();

            this.Version = (byte)((data & 0xF0) >> 4); // take only upper 4 bits
            this.Flags   = (byte)((data & 0x0F) >> 0); // take only lower 4 bits

            // file name
            this.FilePath = H5Utils.ReadNullTerminatedString(reader, pad: false);

            // full object path
            this.FullObjectPath = H5Utils.ReadNullTerminatedString(reader, pad: false);
        }
        private Stream EnsureStream()
        {
            if (_stream is null)
            {
                var name     = _heap.GetObjectName(_slot.NameHeapOffset);
                var filePath = H5Utils.ConstructExternalFilePath(name, _datasetAccess);

                if (!File.Exists(filePath))
                {
                    throw new Exception($"External file '{filePath}' does not exist.");
                }

                _stream = File.OpenRead(filePath);
                _stream.Seek((long)_slot.Offset, SeekOrigin.Begin);
            }

            return(_stream);
        }
        public ExtensibleArrayIndexBlock(H5BinaryReader reader, Superblock superblock, ExtensibleArrayHeader header, uint chunkSizeLength)
        {
            // H5EAiblock.c (H5EA__iblock_alloc)
            ulong secondaryBlockDataBlockAddressCount = 2 * (ulong)Math.Log(header.SecondaryBlockMinimumDataBlockPointerCount, 2);
            ulong dataBlockPointerCount      = (ulong)(2 * (header.SecondaryBlockMinimumDataBlockPointerCount - 1));
            ulong secondaryBlockPointerCount = header.SecondaryBlockCount - secondaryBlockDataBlockAddressCount;

            // signature
            var signature = reader.ReadBytes(4);

            H5Utils.ValidateSignature(signature, ExtensibleArrayIndexBlock.Signature);

            // version
            this.Version = reader.ReadByte();

            // client ID
            this.ClientID = (ClientID)reader.ReadByte();

            // header address
            this.HeaderAddress = superblock.ReadOffset(reader);

            // elements
            this.Elements = ArrayIndexUtils.ReadElements(reader, superblock, header.IndexBlockElementsCount, this.ClientID, chunkSizeLength);

            // data block addresses
            this.DataBlockAddresses = new ulong[dataBlockPointerCount];

            for (ulong i = 0; i < dataBlockPointerCount; i++)
            {
                this.DataBlockAddresses[i] = superblock.ReadOffset(reader);
            }

            // secondary block addresses
            this.SecondaryBlockAddresses = new ulong[secondaryBlockPointerCount];

            for (ulong i = 0; i < secondaryBlockPointerCount; i++)
            {
                this.SecondaryBlockAddresses[i] = superblock.ReadOffset(reader);
            }

            // checksum
            this.Checksum = reader.ReadUInt32();
        }
        public DriverInfoMessage(H5BinaryReader reader) : base(reader)
        {
            // version
            this.Version = reader.ReadByte();

            // driver id
            this.DriverId = H5Utils.ReadFixedLengthString(reader, 8);

            // driver info size
            this.DriverInfoSize = reader.ReadUInt16();

            // driver info
            this.DriverInfo = this.DriverId switch
            {
                "NCSAmulti" => new MultiDriverInfo(reader),
                "NCSAfami" => new FamilyDriverInfo(reader),
                _ => throw new NotSupportedException($"The driver ID '{this.DriverId}' is not supported.")
            };
        }
        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.")
            });
Example #30
0
        public static DataBlockElement[] ReadElements(H5BinaryReader reader,
                                                      Superblock superblock,
                                                      ulong elementsCount,
                                                      ClientID clientID,
                                                      uint chunkSizeLength)
        {
            var elements = new DataBlockElement[elementsCount];

            switch (clientID)
            {
            case ClientID.NonFilteredDatasetChunks:

                for (ulong i = 0; i < elementsCount; i++)
                {
                    elements[i] = new DataBlockElement()
                    {
                        Address = superblock.ReadOffset(reader)
                    };
                }

                break;

            case ClientID.FilteredDatasetChunks:

                for (ulong i = 0; i < elementsCount; i++)
                {
                    elements[i] = new DataBlockElement()
                    {
                        Address    = superblock.ReadOffset(reader),
                        ChunkSize  = (uint)H5Utils.ReadUlong(reader, chunkSizeLength),
                        FilterMask = reader.ReadUInt32()
                    };
                }

                break;

            default:
                throw new Exception($"Client ID '{clientID}' is not supported.");
            }

            return(elements);
        }