예제 #1
0
        private static void GetHeaderValues(ref BinaryBufferReader reader,
                                            out int sectorSize,
                                            out int shortSectorSize,
                                            out int satSectorCount,
                                            out int firstSecIdDirectoryStream,
                                            out uint standardStreamSizeThreshold,
                                            out int firstSecIdSsat,
                                            out uint ssatSectorCount,
                                            out int firstSecIdExtendedMsat,
                                            out int msatExtraSectorCount)
        {
            if (!reader.ReadSpan(8).SequenceEqual(HEADER_SIGNATURE))
            {
                throw new CdfException(Errors.HeaderSignatureMissing);
            }

            reader.Position += 22;

            var sectorSizeExponent = reader.ReadUInt16();

            if (sectorSizeExponent < 7)
            {
                throw new CdfException(Errors.SectorSizeTooSmall);
            }
            sectorSize = (int)Math.Pow(2, sectorSizeExponent);

            var shortSectorSizeExponent = reader.ReadUInt16();

            if (shortSectorSizeExponent > sectorSizeExponent)
            {
                throw new CdfException(Errors.ShortSectorSizeGreaterThanStandardSectorSize);
            }
            shortSectorSize = (int)Math.Pow(2, shortSectorSizeExponent);

            reader.Position += 10;

            satSectorCount            = (int)reader.ReadUInt32();
            firstSecIdDirectoryStream = reader.ReadInt32();

            reader.Position += 4;

            standardStreamSizeThreshold = reader.ReadUInt32();
            firstSecIdSsat         = reader.ReadInt32();
            ssatSectorCount        = reader.ReadUInt32();
            firstSecIdExtendedMsat = reader.ReadInt32();
            msatExtraSectorCount   = reader.ReadInt32();
        }
        public void ReadSpan(int input)
        {
            Reset();
            var buff        = new byte[input];
            var element     = (byte)(input / 2);
            var elementSpan = new ReadOnlySpan <byte>(buff);

            Array.Fill(buff, element);

            _writer.Write(buff);

            var val = _bufferReader.ReadSpan(input);

            Assert.Equal(input, val.Length);

            for (int i = 0; i < buff.Length; i++)
            {
                Assert.Equal(buff[i], val[i]);
            }
        }