Ejemplo n.º 1
0
        private Maybe <BinaryData> GetHNIDBinaryData(NID[] nodePath, HNID hnid)
        {
            if (hnid.IsHID)
            {
                if (hnid.HID.Index == 0)
                {
                    return(Maybe <BinaryData> .NoValue());
                }

                var heapItem = heapOnNodeReader.GetHeapItem(nodePath, hnid.HID);

                return(Maybe <BinaryData> .OfValue(heapItem));
            }

            if (hnid.IsNID)
            {
                var subnodePath = new List <NID>(nodePath)
                {
                    hnid.NID
                };

                var generator = BinaryDataGenerator.New();

                foreach (var block in dataTreeReader.Read(subnodePath.ToArray(), Maybe <int> .NoValue()))
                {
                    generator.Append(block);
                }

                return(generator.GetData());
            }

            return(Maybe <BinaryData> .NoValue());
        }
Ejemplo n.º 2
0
 public BinaryData Encode(HNPAGEHDR value)
 {
     return
         (BinaryDataGenerator
          .New()
          .Append((short)value.PageMapOffset)
          .GetData());
 }
Ejemplo n.º 3
0
 public BinaryData Encode(HNBITMAPHDR value)
 {
     return
         (BinaryDataGenerator
          .New()
          .Append((short)value.PageMapOffset)
          .Append(value.FillLevel)
          .GetData());
 }
Ejemplo n.º 4
0
        private BinaryData Encode(BinaryData data, PageTrailer pageTrailer)
        {
            var dataGenerator = BinaryDataGenerator.New();

            dataGenerator.Append(data);
            dataGenerator.Append(pageTrailer, pageTrailerEncoder);

            return(dataGenerator.GetData());
        }
Ejemplo n.º 5
0
 public BinaryData Encode(ExternalDataBlock value)
 {
     return
         (BinaryDataGenerator.New()
          .Append(value.Data)
          .Append(value.Padding)
          .Append(value.Trailer, blockTrailerEncoder)
          .GetData());
 }
Ejemplo n.º 6
0
 public BinaryData Encode(HNPAGEMAP value)
 {
     return
         (BinaryDataGenerator
          .New()
          .Append((short)value.AllocationCount)
          .Append((short)value.FreeCount)
          .Append(value.AllocationTable)
          .GetData());
 }
Ejemplo n.º 7
0
        public BinaryData Encode(BREF value)
        {
            var generator = BinaryDataGenerator.New();

            return
                (generator
                 .Append(value.BlockId, bidEncoder)
                 .Append(value.ByteIndex, biEncoder)
                 .GetData());
        }
Ejemplo n.º 8
0
        public BinaryData Encode(IBBTEntry value)
        {
            var generator = BinaryDataGenerator.New();

            return
                (generator
                 .Append(value.Key, bidEncoder)
                 .Append(value.ChildPageBlockReference, brefEncoder)
                 .GetData());
        }
Ejemplo n.º 9
0
 public BinaryData Encode(BlockTrailer value)
 {
     return
         (BinaryDataGenerator.New()
          .Append((short)value.AmountOfData)
          .Append((short)value.BlockSignature)
          .Append(value.DataCrc)
          .Append(value.BlockId, bidEncoder)
          .GetData());
 }
Ejemplo n.º 10
0
 public BinaryData Encode(PageTrailer value)
 {
     return
         (BinaryDataGenerator.New()
          .Append((byte)value.PageType)
          .Append((byte)value.PageTypeRepeat)
          .Append((short)value.PageSignature)
          .Append(value.Crc32ForPageData)
          .Append(value.PageBlockId.Value)
          .GetData());
 }
Ejemplo n.º 11
0
        public BinaryData Encode(LBBTEntry value)
        {
            var generator = BinaryDataGenerator.New();

            return
                (generator
                 .Append(value.BlockReference, brefEncoder)
                 .Append(value.ByteCountOfRawDataInReferencedBlockExcludingTrailerAndAlignmentPadding, int32Encoder)
                 .Append(value.NumberOfReferencesToThisBlock, int32Encoder)
                 .Append(value.Padding)
                 .GetData());
        }
Ejemplo n.º 12
0
        private BinaryData EncodeIndexBlock(Tuple <TKey, HID>[] blockItems)
        {
            var generator = BinaryDataGenerator.New();

            foreach (var item in blockItems)
            {
                generator.Append(item.Item1, keyEncoder);
                generator.Append(item.Item2, hidEncoder);
            }

            return(generator.GetData());
        }
Ejemplo n.º 13
0
 public BinaryData Encode(HNHDR value)
 {
     return
         (BinaryDataGenerator
          .New()
          .Append((short)value.PageMapOffset)
          .Append((byte)value.BlockSignature)
          .Append((byte)value.ClientSignature)
          .Append(value.UserRoot.Value)
          .Append(value.FillLevel)
          .GetData());
 }
Ejemplo n.º 14
0
        private BinaryData EncodeLeafBlock(Tuple <TKey, TValue>[] blockItems)
        {
            var generator = BinaryDataGenerator.New();

            foreach (var item in blockItems)
            {
                generator.Append(item.Item1, keyEncoder);
                generator.Append(item.Item2, valueEncoder);
            }

            return(generator.GetData());
        }
Ejemplo n.º 15
0
        private BinaryData EncodeSLBlock(SLEntry[] blockEntries)
        {
            var generator = BinaryDataGenerator.New();

            generator.Append((byte)0x02);
            generator.Append((byte)0x00);
            generator.Append((short)blockEntries.Length);
            generator.Append(BinaryData.OfSize(4));

            Array.ForEach(blockEntries, e => generator = generator.Append(e, slEntryEncoder));

            return(generator.GetData());
        }
Ejemplo n.º 16
0
        public BinaryData Encode(LNBTEntry value)
        {
            var generator = BinaryDataGenerator.New();

            return
                (generator
                 .Append(value.NodeId, nidEncoder)
                 .Append(value.DataBlockId, bidEncoder)
                 .Append(value.SubnodeBlockId, bidEncoder)
                 .Append(value.ParentNodeId, nidEncoder)
                 .Append(value.Padding)
                 .GetData());
        }
Ejemplo n.º 17
0
        public BinaryData Encode(BTPage value)
        {
            var generator = BinaryDataGenerator.New();

            return
                (generator
                 .Append(value.Entries)
                 .Append(value.Entries.Length, int32Encoder, 1)
                 .Append(value.MaximumNumberOfEntriesInPage, int32Encoder, 1)
                 .Append(value.EntrySize, int32Encoder, 1)
                 .Append(value.PageLevel, int32Encoder, 1)
                 .Append(value.PageTrailer, pageTrailerEncoder)
                 .GetData());
        }
Ejemplo n.º 18
0
 private BinaryData GetDataToCalculateCrc32(
     BinaryData encodedExternalBlockIds,
     int numberOfExternalBlockIds,
     int totalNumberOfBytesInReferencedBlocks)
 {
     return
         (BinaryDataGenerator.New()
          .Append((byte)0x01)
          .Append((byte)blockLevel)
          .Append((short)numberOfExternalBlockIds)
          .Append(totalNumberOfBytesInReferencedBlocks)
          .Append(encodedExternalBlockIds)
          .GetData());
 }
Ejemplo n.º 19
0
        public IB ExtendSingle()
        {
            var extensionOffset = IB.OfValue(dataStream.Length);

            var numberOfAMapsSoFar = Convert.ToInt32(extensionOffset.Subtract(OffsetOfFirstAMap) / AMapExtensionSize);
            var numberOfPMapsSoFar = Convert.ToInt32(extensionOffset.Add(0x512).Subtract(OffsetOfFirstPMap) / PMapExtensionSize);

            var createPMap  = extensionOffset.Add(0x512).Subtract(OffsetOfFirstPMap) % PMapExtensionSize == 0;
            var createFMap  = numberOfAMapsSoFar == 127 || numberOfAMapsSoFar == 495;
            var createFPMap = numberOfPMapsSoFar == 127 * 8 || numberOfPMapsSoFar == 495 * 8;

            var amap = CreateAMap(extensionOffset, createPMap, createFMap, createFPMap);

            var dataGenerator = BinaryDataGenerator.New();

            dataGenerator.Append(amap, amapEncoder);

            if (createPMap)
            {
                dataGenerator.Append(CreatePMap(extensionOffset + 0x200), pmapEncoder);
            }

            if (createFMap)
            {
                dataGenerator.Append(CreateFMap(extensionOffset + 0x400), fmapEncoder);
            }

            if (createFPMap)
            {
                dataGenerator.Append(CreateFPMap(extensionOffset + 0x600), fpmapEncoder);
            }

            dataGenerator.FillTo(AMapExtensionSize);

            dataGenerator.WriteTo(dataStream);

            headerUsageProvider.Use(
                header =>
                header
                .SetRoot(
                    header
                    .Root
                    .SetFileEOF(extensionOffset + AMapExtensionSize)
                    .SetLastAMapOffset(extensionOffset)
                    .SetFreeSpaceInAllAMaps(header.Root.AMapFree + AMapExtensionSize - GetDefaultAllocationsSize(createPMap, createFMap, createFPMap))));

            return(extensionOffset);
        }
Ejemplo n.º 20
0
        private BinaryData CreateAllocationTable(
            BinaryData[] items,
            int sizeOfTheHeader)
        {
            var generator = BinaryDataGenerator.New();

            var itemOffset = sizeOfTheHeader;

            for (var i = 0; i < items.Length + 1; i++)
            {
                generator  = generator.Append((short)itemOffset);
                itemOffset = itemOffset + items[i].Length;
            }

            return(generator.GetData());
        }
Ejemplo n.º 21
0
        private Tuple <PropertyId, BinaryData> AllocatePropertyOnTheHN(
            PropertyTag propertyTag,
            PropertyValue propertyValue,
            IHeapOnNodeGenerator hnGenerator)
        {
            var propertyValueInHN =
                BinaryDataGenerator
                .New()
                .Append((short)propertyTag.Type.Value)
                .Append(propertyValue.Value)
                .GetData();

            var hid = hnGenerator.AllocateItem(propertyValueInHN);

            var hnid = new HNID(hid);

            return(Tuple.Create(propertyTag.Id, hnidEncoder.Encode(hnid)));
        }
Ejemplo n.º 22
0
        public BinaryData Encode(Root value)
        {
            var generator = BinaryDataGenerator.New();

            return
                (generator
                 .Append(value.Reserved, int32Encoder)
                 .Append(value.FileEOF, int64Encoder)
                 .Append(value.AMapLast, int64Encoder)
                 .Append(value.AMapFree, int64Encoder)
                 .Append(value.PMapFree, int64Encoder)
                 .Append(value.NBTRootPage, brefEncoder)
                 .Append(value.BBTRootPage, brefEncoder)
                 .Append(value.AMapValid, int32Encoder, 1)
                 .Append(value.BReserved, int32Encoder, 1)
                 .Append(value.WReserved, int32Encoder, 2)
                 .GetData());
        }
Ejemplo n.º 23
0
        private BinaryData EncodeBlock(
            ExternalDataBlockForHeapOnNode block,
            BinaryData encodedHeader)
        {
            var pageMap =
                new HNPAGEMAP(
                    block.NumberOfItems + 1,
                    0,
                    CreateAllocationTable(block.Items, block.HeaderSize));

            return
                (BinaryDataGenerator
                 .New()
                 .Append(encodedHeader)
                 .Append(block.Items)
                 .FillTo(block.RawByteCountWithoutPageMapWithPadding)
                 .Append(pageMap, pageMapEncoder)
                 .GetData());
        }