Esempio n. 1
0
        public override void Write(Tag tag, Writer writer)
        {
            header.Write(writer);

            long bytesToWrite = header.Size;

            bool allFramesUnsynchronized = true;

            foreach (Frame frame in tag.Frames)
            {
                long pos0    = writer.Position;
                int  unsync0 = writer.UnsynchronizationCounter;

                frame.Codec.Write(writer, frame);

                int  unsync1 = writer.UnsynchronizationCounter;
                long pos1    = writer.Position;

                if (unsync0 == unsync1)
                {
                    allFramesUnsynchronized = false;
                }

                if (header.size != HeaderV2.sizeUnitinialized)
                {
                    long writtenBytes = pos1 - pos0;

                    bytesToWrite -= writtenBytes;

                    if (bytesToWrite < 0)
                    {
                        throw new Exception(GetType().Name + ": frame or header sizes wrong");
                    }
                }
            }

            if (header.size != HeaderV2.sizeUnitinialized)
            {
                for (long i = bytesToWrite; i > 0; i--)
                {
                    writer.WriteByte(0);
                }
            }

            if (header.VersionMajor == 4)
            {
                long pos0 = writer.Position;

                writer.Seek(0, SeekOrigin.Begin);

                header.IsUnsynchronized = allFramesUnsynchronized;
                header.Write(writer);

                writer.Seek(pos0, SeekOrigin.Begin);
            }
        }
Esempio n. 2
0
        private static void TestHeaderV2()
        {
            HeaderV2 header = new HeaderV2();

            header.IgnoreUnsupportedFlags = true;

            byte[] data =
            {
                // File identificator
                (byte)'I', (byte)'D', (byte)'3',

                // Version
                3,                 0,

                // Flags
                0xE0,

                // Size
                0,                 0,         0, 0
            };

            using (Reader reader = new Reader(data))
            {
                header.Read(reader);
                header.CheckVersion(Version.v2_3);
            }

            UnitTest.Test(header.HeaderSize == 10);
            UnitTest.Test(header.VersionMajor == 3);
            UnitTest.Test(header.VersionMinor == 0);
            UnitTest.Test(header.IsUnsynchronized);
            UnitTest.Test(header.HasExtendedHeader);
            UnitTest.Test(header.HasExperimentalStage);

            using (Writer writer = new Writer())
            {
                header.Write(writer);
                UnitTest.Test(ArrayUtils.IsEqual(writer.OutData, data));
            }
        }