Ejemplo n.º 1
0
        public static int WriteMultipageItemBlock(IPage page, DbItem item, long offset)
        {
            if (offset < 0 || offset >= item.RawData.LongLength)
            {
                throw new ArgumentOutOfRangeException(nameof(offset));
            }

            MultipageItemPageHeader header = GetMultipageItemPageHeader(page);

            if (item.GetAllocationType(page.Length) == AllocationType.SinglePage)
            {
                throw new PageFormatException("Unable to add item block on page. Item allocation type is single page.");
            }

            int last          = Math.Min(page.Length - header.Length, (int)(item.RawData.LongLength - offset)) - 1;
            int contentOffset = header.Length;

            if (offset == 0)
            {
                // we should write the length of the object
                var lengthBytes = BitConverter.GetBytes(item.RawData.LongLength);
                lengthBytes.CopyTo(page.Content, header.Length);

                last          -= 8;
                contentOffset += 8;
            }

            for (long i = 0; i <= last; i++)
            {
                page.Content[i + contentOffset] = item.RawData[i + offset];
            }

            return(last + 1);
        }
Ejemplo n.º 2
0
        public static long ReadMultipageItemLength(IPage page)
        {
            MultipageItemPageHeader header = GetMultipageItemPageHeader(page);

            if (header.PreviousPageIndex != -1)
            {
                throw new PageFormatException("This page is not the start page of multipage item.");
            }

            return(BitConverter.ToInt64(page.Content, header.Length));
        }
Ejemplo n.º 3
0
        public static byte[] ReadMultipageItemBlock(IPage page, int length)
        {
            MultipageItemPageHeader header = GetMultipageItemPageHeader(page);

            var offset = header.Length;

            // skip object length marker if we are on the start page
            if (header.PreviousPageIndex == -1)
            {
                offset += 8;
            }

            return(ReadBlock(page, Math.Min(length, page.Length - offset), offset));
        }
Ejemplo n.º 4
0
        public static PageHeaderBase GetPageHeader(IPage page)
        {
            PageHeaderBase ph;
            PageType       pt = PageHeaderBase.GetPageType(page);

            switch (pt)
            {
            case PageType.FreeSpaceMap:
                ph = new FreeSpaceMapPageHeader();
                ph.Read(page);
                return(ph);

            case PageType.Heading:
                ph = new HeadingPageHeader();
                ph.Read(page);
                return(ph);

            case PageType.MultipageItem:
                ph = new MultipageItemPageHeader();
                ph.Read(page);
                return(ph);

            case PageType.FixedSizeItem:
                ph = new FixedSizeItemsPageHeader();
                ph.Read(page);
                return(ph);

            case PageType.BPlusTree:
                ph = new BPlusTreeNodePageHeader();
                ph.Read(page);
                return(ph);

            case PageType.RadixTree:
                ph = new RadixTreeNodesPageHeader();
                ph.Read(page);
                return(ph);
            }
            return(null);
        }