当前位置: 首页>>代码示例>>C#>>正文


C# ByteVector.ToUInt方法代码示例

本文整理汇总了C#中ByteVector.ToUInt方法的典型用法代码示例。如果您正苦于以下问题:C# ByteVector.ToUInt方法的具体用法?C# ByteVector.ToUInt怎么用?C# ByteVector.ToUInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ByteVector的用法示例。


在下文中一共展示了ByteVector.ToUInt方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AudioHeader

 private AudioHeader(ByteVector data, TagLib.File file, long position)
 {
     this.duration = TimeSpan.Zero;
     this.stream_length = 0L;
     if (data.Count < 4)
     {
         throw new CorruptFileException("Insufficient header length.");
     }
     if (data[0] != 0xff)
     {
         throw new CorruptFileException("First byte did not match MPEG synch.");
     }
     if (((data[1] & 230) <= 0xe0) || ((data[1] & 0x18) == 8))
     {
         throw new CorruptFileException("Second byte did not match MPEG synch.");
     }
     this.flags = data.ToUInt();
     if (((this.flags >> 12) & 15) == 15)
     {
         throw new CorruptFileException("Header uses invalid bitrate index.");
     }
     if (((this.flags >> 10) & 3) == 3)
     {
         throw new CorruptFileException("Invalid sample rate.");
     }
     this.xing_header = TagLib.Mpeg.XingHeader.Unknown;
     this.vbri_header = TagLib.Mpeg.VBRIHeader.Unknown;
     file.Seek(position + TagLib.Mpeg.XingHeader.XingHeaderOffset(this.Version, this.ChannelMode));
     ByteVector vector = file.ReadBlock(0x10);
     if ((vector.Count == 0x10) && vector.StartsWith(TagLib.Mpeg.XingHeader.FileIdentifier))
     {
         this.xing_header = new TagLib.Mpeg.XingHeader(vector);
     }
     if (!this.xing_header.Present)
     {
         file.Seek(position + TagLib.Mpeg.VBRIHeader.VBRIHeaderOffset());
         ByteVector vector2 = file.ReadBlock(0x18);
         if ((vector2.Count == 0x18) && vector2.StartsWith(TagLib.Mpeg.VBRIHeader.FileIdentifier))
         {
             this.vbri_header = new TagLib.Mpeg.VBRIHeader(vector2);
         }
     }
 }
开发者ID:shankithegreat,项目名称:commanderdotnet,代码行数:43,代码来源:AudioHeader.cs

示例2: CreateIFDEntry

		/// <summary>
		///    Creates an IFDEntry from the given values. This method is used for
		///    every entry. Custom parsing can be hooked in by overriding the
		///    <see cref="ParseIFDEntry(ushort,ushort,uint,long,uint)"/> method.
		/// </summary>
		/// <param name="tag">
		///    A <see cref="System.UInt16"/> with the tag of the entry.
		/// </param>
		/// <param name="type">
		///    A <see cref="System.UInt16"/> with the type of the entry.
		/// </param>
		/// <param name="count">
		///    A <see cref="System.UInt32"/> with the data count of the entry.
		/// </param>
		/// <param name="base_offset">
		///    A <see cref="System.Int64"/> with the base offset which every
		///    offsets in the IFD are relative to.
		/// </param>
		/// <param name="offset_data">
		///    A <see cref="ByteVector"/> containing exactly 4 byte with the data
		///    of the offset of the entry. Since this field isn't interpreted as
		///    an offset if the data can be directly stored in the 4 byte, we
		///    pass the <see cref="ByteVector"/> to easier interpret it.
		/// </param>
		/// <param name="max_offset">
		///    A <see cref="System.UInt32"/> with the maximal offset to consider for
		///    the IFD.
		/// </param>
		/// <returns>
		///    A <see cref="IFDEntry"/> with the given parameter.
		/// </returns>
		private IFDEntry CreateIFDEntry (ushort tag, ushort type, uint count, long base_offset, ByteVector offset_data, uint max_offset)
		{
			uint offset = offset_data.ToUInt (is_bigendian);

			// Fix the type for the IPTC tag.
			// From http://www.awaresystems.be/imaging/tiff/tifftags/iptc.html
			// "Often times, the datatype is incorrectly specified as LONG. "
			if (tag == (ushort) IFDEntryTag.IPTC && type == (ushort) IFDEntryType.Long) {
				type = (ushort) IFDEntryType.Byte;
			}

			var ifd_entry = ParseIFDEntry (tag, type, count, base_offset, offset);
			if (ifd_entry != null)
				return ifd_entry;

			if (count > 0x10000000) {
				// Some Nikon files are known to exhibit this corruption (or "feature").
				file.MarkAsCorrupt ("Impossibly large item count");
				return null;
			}

			// then handle the values stored in the offset data itself
			if (count == 1) {
				if (type == (ushort) IFDEntryType.Byte)
					return new ByteIFDEntry (tag, offset_data[0]);

				if (type == (ushort) IFDEntryType.SByte)
					return new SByteIFDEntry (tag, (sbyte)offset_data[0]);

				if (type == (ushort) IFDEntryType.Short)
					return new ShortIFDEntry (tag, offset_data.Mid (0, 2).ToUShort (is_bigendian));

				if (type == (ushort) IFDEntryType.SShort)
					return new SShortIFDEntry (tag, (short) offset_data.Mid (0, 2).ToUShort (is_bigendian));

				if (type == (ushort) IFDEntryType.Long)
					return new LongIFDEntry (tag, offset_data.ToUInt (is_bigendian));

				if (type == (ushort) IFDEntryType.SLong)
					return new SLongIFDEntry (tag, offset_data.ToInt (is_bigendian));

			}

			if (count == 2) {
				if (type == (ushort) IFDEntryType.Short) {
					ushort [] data = new ushort [] {
						offset_data.Mid (0, 2).ToUShort (is_bigendian),
						offset_data.Mid (2, 2).ToUShort (is_bigendian)
					};

					return new ShortArrayIFDEntry (tag, data);
				}

				if (type == (ushort) IFDEntryType.SShort) {
					short [] data = new short [] {
						(short) offset_data.Mid (0, 2).ToUShort (is_bigendian),
						(short) offset_data.Mid (2, 2).ToUShort (is_bigendian)
					};

					return new SShortArrayIFDEntry (tag, data);
				}
			}

			if (count <= 4) {
				if (type == (ushort) IFDEntryType.Undefined)
					return new UndefinedIFDEntry (tag, offset_data.Mid (0, (int)count));

				if (type == (ushort) IFDEntryType.Ascii) {
					string data = offset_data.Mid (0, (int)count).ToString ();
//.........这里部分代码省略.........
开发者ID:JohnThomson,项目名称:taglib-sharp,代码行数:101,代码来源:IFDReader.cs

示例3: AudioHeader

		/// <summary>
		///    Constructs and initializes a new instance of <see
		///    cref="AudioHeader" /> by reading its contents from a
		///    <see cref="ByteVector" /> object and its Xing Header from
		///    the appropriate location in the specified file.
		/// </summary>
		/// <param name="data">
		///    A <see cref="ByteVector" /> object containing the header
		///    to read.
		/// </param>
		/// <param name="file">
		///    A <see cref="TagLib.File" /> object to read the Xing
		///    header from.
		/// </param>
		/// <param name="position">
		///    A <see cref="long" /> value indicating the position in
		///    <paramref name="file" /> at which the header begins.
		/// </param>
		/// <exception cref="CorruptFileException">
		///    <paramref name="data" /> is less than 4 bytes long,
		///    does not begin with a MPEG audio synch, has a negative
		///    bitrate, or has a sample rate of zero.
		/// </exception>
		private AudioHeader (ByteVector data, TagLib.File file,
		                     long position)
		{
			this.duration = TimeSpan.Zero;
			stream_length = 0;
			
			if (data.Count < 4)
				throw new CorruptFileException (
					"Insufficient header length.");
			
			if (data [0] != 0xFF)
				throw new CorruptFileException (
					"First byte did not match MPEG synch.");
			
			if (data [1] < 0xE0)
				throw new CorruptFileException (
					"Second byte did not match MPEG synch.");
			
			flags = data.ToUInt ();
			
			if (((flags >> 12) & 0x0F) == 0x0F)
				throw new CorruptFileException (
					"Header uses invalid bitrate index.");
			
			if (((flags >> 10) & 0x03) == 0x03)
				throw new CorruptFileException (
					"Invalid sample rate.");

			xing_header = XingHeader.Unknown;
			
			vbri_header = VBRIHeader.Unknown;
			
			// Check for a Xing header that will help us in
			// gathering information about a VBR stream.
			file.Seek (position + XingHeader.XingHeaderOffset (
				Version, ChannelMode));
				
			ByteVector xing_data = file.ReadBlock (16);
			if (xing_data.Count == 16 && xing_data.StartsWith (
				XingHeader.FileIdentifier))
				xing_header = new XingHeader (xing_data);

			if (xing_header.Present)
				return;
			
			// A Xing header could not be found, next chec for a
			// Fraunhofer VBRI header.
			file.Seek (position + VBRIHeader.VBRIHeaderOffset ());

			// Only get the first 24 bytes of the Header.
			// We're not interested in the TOC entries.
			ByteVector vbri_data = file.ReadBlock (24);
			if (vbri_data.Count == 24 &&
				vbri_data.StartsWith(VBRIHeader.FileIdentifier))
			vbri_header = new VBRIHeader (vbri_data);
		}
开发者ID:bossaia,项目名称:alexandrialibrary,代码行数:79,代码来源:AudioHeader.cs

示例4: CheckCRC

		/// <summary>
		///    Checks the CRC for a Chunk.
		/// </summary>
		/// <param name="chunk_type">
		///    A <see cref="ByteVector"/> whith the Chunk type
		/// </param>
		/// <param name="chunk_data">
		///    A <see cref="ByteVector"/> with the Chunk data.
		/// </param>
		/// <param name="crc_data">
		///    A <see cref="ByteVector"/> with the read CRC data.
		/// </param>
		private static void CheckCRC (ByteVector chunk_type, ByteVector chunk_data, ByteVector crc_data)
		{
			ByteVector computed_crc = ComputeCRC (chunk_type, chunk_data);

			if (computed_crc != crc_data)
				throw new CorruptFileException (
					String.Format ("CRC check failed for {0} Chunk (expected: 0x{1:X4}, read: 0x{2:X4}",
					               chunk_type.ToString (), computed_crc.ToUInt (), crc_data.ToUInt ()));
		}
开发者ID:rygos,项目名称:iTagger,代码行数:21,代码来源:File.cs

示例5: GetHeaderError

        private static string GetHeaderError(ByteVector data)
        {
            if (data.Count < 4)
                return "Insufficient header length.";

            if (data [0] != 0xFF)
                return "First byte did not match MPEG synch.";

            // Checking bits from high to low:
            //
            // First 3 bits MUST be set. Bits 4 and 5 can
            // be 00, 10, or 11 but not 01. One or more of
            // bits 6 and 7 must be set. Bit 8 can be
            // anything.
            if ((data [1] & 0xE6) <= 0xE0 || (data [1] & 0x18) == 0x08)
                return "Second byte did not match MPEG synch.";

            uint flags = data.ToUInt ();

            if (((flags >> 12) & 0x0F) == 0x0F)
                return "Header uses invalid bitrate index.";

            if (((flags >> 10) & 0x03) == 0x03)
                return "Invalid sample rate.";

            return null;
        }
开发者ID:kennethito,项目名称:taglib-sharp,代码行数:27,代码来源:AudioHeader.cs

示例6: AudioHeader

        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="AudioHeader" /> by reading its contents from a
        ///    <see cref="ByteVector" /> object and its Xing Header from
        ///    the appropriate location in the specified file.
        /// </summary>
        /// <param name="data">
        ///    A <see cref="ByteVector" /> object containing the header
        ///    to read.
        /// </param>
        /// <param name="file">
        ///    A <see cref="TagLib.File" /> object to read the Xing
        ///    header from.
        /// </param>
        /// <param name="position">
        ///    A <see cref="long" /> value indicating the position in
        ///    <paramref name="file" /> at which the header begins.
        /// </param>
        /// <exception cref="CorruptFileException">
        ///    <paramref name="data" /> is less than 4 bytes long,
        ///    does not begin with a MPEG audio synch, has a negative
        ///    bitrate, or has a sample rate of zero.
        /// </exception>
        private AudioHeader(ByteVector data, TagLib.File file,
		                     long position)
        {
            this.duration = TimeSpan.Zero;
            stream_length = 0;

            string error = GetHeaderError(data);
            if (error != null) {
                throw new CorruptFileException (error);
            }

            flags = data.ToUInt ();

            xing_header = XingHeader.Unknown;

            vbri_header = VBRIHeader.Unknown;

            info_header = XingHeader.Unknown;

            // Check for a Xing header that will help us in
            // gathering information about a VBR stream.
            file.Seek (position + XingHeader.XingHeaderOffset (
                Version, ChannelMode));

            ByteVector xing_data = file.ReadBlock (16);
            if (xing_data.Count == 16)
            {
                if (xing_data.StartsWith(XingHeader.XingFileIdentifier))
                {
                    xing_header = new XingHeader(xing_data);

                    if (xing_header.Present)
                        return;
                }

                if (xing_data.StartsWith(XingHeader.InfoFileIdentifier))
                {
                    info_header = new XingHeader(xing_data);

                    if (info_header.Present)
                        return;
                }
            }

            // A Xing header could not be found, next chec for a
            // Fraunhofer VBRI header.
            file.Seek (position + VBRIHeader.VBRIHeaderOffset ());

            // Only get the first 24 bytes of the Header.
            // We're not interested in the TOC entries.
            ByteVector vbri_data = file.ReadBlock (24);
            if (vbri_data.Count == 24 &&
                vbri_data.StartsWith(VBRIHeader.FileIdentifier))
            vbri_header = new VBRIHeader (vbri_data);
        }
开发者ID:kennethito,项目名称:taglib-sharp,代码行数:78,代码来源:AudioHeader.cs

示例7: Parse

		/// <summary>
		///    Populates the current instance by parsing the contents of
		///    a raw AudibleMetadata tag.
		/// </summary>
		/// <param name="data">
		///    	A <see cref="ByteVector" /> object containing the whole tag
		/// 	object
		/// </param>
		/// <exception cref="CorruptFileException">
		///    <paramref name="data" /> is less than 128 bytes or does
		///    not start with <see cref="FileIdentifier" />.
		/// </exception>
		private void Parse (ByteVector data)
		{
			String currentKey, currentValue;
			int keyLen, valueLen;
			
			try
			{
				do
				{
					keyLen = (int) data.ToUInt(true);
					data.RemoveRange (0, 4);
					valueLen = (int) data.ToUInt(true);
					data.RemoveRange (0, 4);
					currentKey = data.ToString ( TagLib.StringType.UTF8, 0, keyLen );
					data.RemoveRange (0, keyLen);
					currentValue = data.ToString ( TagLib.StringType.UTF8, 0, valueLen );
					data.RemoveRange (0, valueLen);
					
					tags.Add( new KeyValuePair<string, string>(currentKey, currentValue) );
					
					//StringHandle (currentKey, currentValue);
					
					// if it is not the last item remove the end byte (null terminated)
					if (data.Count != 0)
						data.RemoveRange(0,1);
				}
				while (data.Count >= 4);
			}
			catch (Exception)
			{
				//
			}
			
			if (data.Count != 0)
				throw new CorruptFileException();
		}
开发者ID:hoeness2,项目名称:mcebuddy2,代码行数:48,代码来源:Tag.cs


注:本文中的ByteVector.ToUInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。