Exemplo n.º 1
0
        internal static ExtendedTagHeaderV4 Create(bool updateFlag, bool crcPresent, bool restrictionPresent,
                                                   byte restriction, ReadOnlyCollection<byte> crc32)
        {
            var extendedHeader = new ExtendedTagHeaderV4();

            extendedHeader.UpdateTag = updateFlag;
            extendedHeader.CrcDataPresent = crcPresent;
            extendedHeader.RestrictionPresent = restrictionPresent;
            extendedHeader.Restriction = restriction;
            extendedHeader.Crc32 = crc32;

            return extendedHeader;
        }
Exemplo n.º 2
0
        internal static ExtendedTagHeaderV4 Create(byte[] content)
        {
            var extendedHeader = new ExtendedTagHeaderV4();
            // ignore content[0] ( always 01 )
            byte flagByte = content[1];
            bool updateFlag = (flagByte & 0x40) == 0x40;
            bool crc32Flag = (flagByte & 0x20) == 0x020;
            bool restrictionFlag = (flagByte & 0x10) == 0x10;

            int startIndex = 2;
            if (updateFlag)
            {
                // Read the update content

                //TODO: The length is always 0. hm... better implementation here?
                //var length = content[startIndex];
                startIndex++;

                extendedHeader.UpdateTag = true;
            }

            if (crc32Flag)
            {
                // Read the crc32

                var crcBytes = new byte[5];
                Array.Copy(content, startIndex + 1, crcBytes, 0, 5);

                startIndex += 6;

                extendedHeader.CrcDataPresent = true;
                extendedHeader.Crc32 = new ReadOnlyCollection<byte>(crcBytes);
            }

            if (restrictionFlag)
            {
                // Read the restriction byte

                byte restrictionByte = content[startIndex + 1];

                extendedHeader.RestrictionPresent = true;
                extendedHeader.Restriction = restrictionByte;
            }

            return extendedHeader;
        }