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();
        }
Exemple #2
0
        private void ReadFixedArray(Span <byte> buffer, ulong chunkSize)
        {
            var chunkSizeLength = this.ComputeChunkSizeLength(chunkSize);
            var header          = new FixedArrayHeader(this.Context.Reader, this.Context.Superblock, chunkSizeLength);
            var dataBlock       = header.DataBlock;

            IEnumerable <DataBlockElement> elements;

            if (dataBlock.PageCount > 0)
            {
                var pages = new List <DataBlockPage>((int)dataBlock.PageCount);

                for (int i = 0; i < (int)dataBlock.PageCount; i++)
                {
                    var page = new DataBlockPage(this.Context.Reader, this.Context.Superblock, dataBlock.ElementsPerPage, dataBlock.ClientID, chunkSizeLength);
                    pages.Add(page);
                }

                elements = pages.SelectMany(page => page.Elements);
            }
            else
            {
                elements = dataBlock.Elements.AsEnumerable();
            }

            var offset     = 0UL;
            var index      = 0UL;
            var enumerator = elements.GetEnumerator();

            for (ulong i = 0; i < header.EntriesCount; i++)
            {
                enumerator.MoveNext();
                var element = enumerator.Current;

                // if page/element is initialized (see also datablock.PageBitmap)
                if (element.Address > 0)
                {
                    this.SeekSliceAndReadChunk(offset, chunkSize, element.ChunkSize, element.Address, buffer);
                }

                offset += chunkSize;
                index++;
            }
        }
        public FixedArrayDataBlock(H5BinaryReader reader, Superblock superblock, FixedArrayHeader header, Func <H5BinaryReader, T> decode)
        {
            // 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 <T> .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);
                this.Elements   = new T[0];
            }
            // elements
            else
            {
                this.PageBitmap = new byte[0];

                this.Elements = Enumerable
                                .Range(0, (int)header.EntriesCount)
                                .Select(i => decode(reader))
                                .ToArray();
            }

            // checksum
            this.Checksum = reader.ReadUInt32();

            // last page element count
            if (header.EntriesCount % this.ElementsPerPage == 0)
            {
                this.LastPageElementCount = this.ElementsPerPage;
            }

            else
            {
                this.LastPageElementCount = header.EntriesCount % this.ElementsPerPage;
            }
        }