コード例 #1
0
        /// <summary>
        ///    Renders the current instance as a raw ID3v2 header.
        /// </summary>
        /// <returns>
        ///    A <see cref="ByteVector" /> object containing the
        ///    rendered header.
        /// </returns>
        public ByteVector Render()
        {
            ByteVector v = new ByteVector();

            v.Add(FileIdentifier);
            v.Add(MajorVersion);
            v.Add(RevisionNumber);
            v.Add((byte)flags);
            v.Add(SynchData.FromUInt(TagSize));
            return(v);
        }
コード例 #2
0
        /// <summary>
        ///    Renders the current instance, encoded in a specified
        ///    ID3v2 version.
        /// </summary>
        /// <param name="version">
        ///    A <see cref="byte" /> value specifying the version of
        ///    ID3v2 to use when encoding the current instance.
        /// </param>
        /// <returns>
        ///    A <see cref="ByteVector" /> object containing the
        ///    rendered version of the current instance.
        /// </returns>
        /// <exception cref="NotImplementedException">
        ///    The version specified in the current instance is
        ///    unsupported.
        /// </exception>
        public ByteVector Render(byte version)
        {
            ByteVector data = new ByteVector();
            ByteVector id   = ConvertId(frame_id, version, true);

            if (id == null)
            {
                throw new NotImplementedException();
            }

            switch (version)
            {
            case 2:
                data.Add(id);
                data.Add(ByteVector.FromUInt(frame_size)
                         .Mid(1, 3));

                return(data);

            case 3:
                ushort new_flags = (ushort)(
                    (((ushort)flags << 1) & 0xE000) |
                    (((ushort)flags << 4) & 0x00C0) |
                    (((ushort)flags >> 1) & 0x0020));

                data.Add(id);
                data.Add(ByteVector.FromUInt(frame_size));
                data.Add(ByteVector.FromUShort(new_flags));

                return(data);

            case 4:
                data.Add(id);
                data.Add(SynchData.FromUInt(frame_size));
                data.Add(ByteVector.FromUShort((ushort)flags));

                return(data);

            default:
                throw new NotImplementedException(
                          "Unsupported tag version.");
            }
        }