예제 #1
0
        public void ParseWeightsTableTest3()
        {
            IReadOnlyList <Bit> data = BitListHelper.CreateBuilder()
                                       .AddInt(0x2D)
                                       .AddByte(0x1)
                                       .AddLong(0x1)
                                       .AddByte(0x2)
                                       .AddLong(0xFFF)
                                       .AddByte(0xF)
                                       .AddLong(0x5)
                                       .AddByte(0xAF)
                                       .AddLong(0xFFA)
                                       .AddByte(0xFF)
                                       .AddLong(0x1).BitList;

            BootstrapSegment segment = streamParser.ParseWeightsTable(new TestIDecodingInputStream(data));

            Assert.IsNotNull(segment);
            WeightsTable weightsTable = segment.WeightsTable;

            Assert.IsNotNull(weightsTable);

            WeightedSymbol[] expectedSymbols =
            {
                new WeightedSymbol(0x1,    0x1),
                new WeightedSymbol(0x2,  0xFFF),
                new WeightedSymbol(0xF,    0x5),
                new WeightedSymbol(0xAF, 0xFFA),
                new WeightedSymbol(0xFF,     1),
            };
            Assert.AreEqual(expectedSymbols, weightsTable);
        }
        private void DecodeFile(FileDecodingInputStream inputStream, BootstrapSegment bootstrapSegment, CancellationToken cancellationToken, IProgressHandler progressHandler)
        {
            FileSegment file = streamParser.ParseFile(inputStream, bootstrapSegment.WeightsTable);
            string      path = Path.Combine(currentDirectory, file.Name);

            using (FileDecodingOutputStream outputStream = new FileDecodingOutputStream(path, platform)) {
                file.FileDecoder.Decode(outputStream, cancellationToken, progressHandler);
            }
        }
예제 #3
0
        public void ParseWeightsTableTest1()
        {
            IReadOnlyList <Bit> data = BitListHelper.CreateBuilder()
                                       .AddInt(0x0).BitList;

            BootstrapSegment segment = streamParser.ParseWeightsTable(new TestIDecodingInputStream(data));

            Assert.IsNotNull(segment);
            WeightsTable weightsTable = segment.WeightsTable;

            Assert.IsNotNull(weightsTable);
            Assert.AreEqual(0, weightsTable.Size);
        }
예제 #4
0
        public void AddWeightsTable(BootstrapSegment segment)
        {
            Guard.IsNotNull(segment, nameof(segment));

            WeightsTable weightsTable = segment.WeightsTable;

            stream.Write(StreamKind.WT_CODE);
            stream.Write(9 * weightsTable.Size);
            foreach (WeightedSymbol symbol in weightsTable)
            {
                stream.Write(symbol.Symbol);
                stream.Write(symbol.Weight);
            }
        }
        private void Decode(string inputFile, string outputFolder, CancellationToken cancellationToken, IProgress <CodingProgressInfo> progress)
        {
            FileDecodingInputStream inputStream = new FileDecodingInputStream(inputFile, platform);

            ITaskProgressController tpc = CreateTaskProgressController(progress, inputStream);

            try {
                if (inputStream.IsEmpty)
                {
                    return;
                }

                StreamKind code = inputStream.ReadStreamFormat();
                if (code != StreamKind.WT_CODE)
                {
                    throw new StreamFormatException();
                }

                tpc.Start();
                directoriesQueue.Enqueue(currentDirectory = outputFolder);
                BootstrapSegment bootstrapSegment = streamParser.ParseWeightsTable(inputStream);
                while (!inputStream.IsEmpty)
                {
                    switch (inputStream.ReadStreamFormat())
                    {
                    case StreamKind.FS_CODE:
                        DecodeFile(inputStream, bootstrapSegment, cancellationToken, tpc);
                        break;

                    case StreamKind.DS_CODE:
                        DecodeDirectory(inputStream);
                        break;

                    default:
                        throw new StreamFormatException();
                    }
                }
                tpc.Finish();
            }
            catch {
                tpc.Error();
                throw;
            }
            finally {
                inputStream.Dispose();
            }
        }
예제 #6
0
        public void ParseWeightsTableTest2()
        {
            IReadOnlyList <Bit> data = BitListHelper.CreateBuilder()
                                       .AddInt(0x9)
                                       .AddByte(0x45)
                                       .AddLong(0x33).BitList;

            BootstrapSegment segment = streamParser.ParseWeightsTable(new TestIDecodingInputStream(data));

            Assert.IsNotNull(segment);
            WeightsTable weightsTable = segment.WeightsTable;

            Assert.IsNotNull(weightsTable);

            WeightedSymbol[] expectedSymbols =
            {
                new WeightedSymbol(0x45, 0x33)
            };
            Assert.AreEqual(expectedSymbols, weightsTable);
        }
 void IStreamBuilder.AddWeightsTable(BootstrapSegment segment)
 {
     Trace += "->AddWeightsTable;";
 }