예제 #1
0
 public void Long()
 {
     Assert.AreEqual(UInt64.MaxValue, ByteVector.FromULong(UInt64.MaxValue).ToULong());
     Assert.AreEqual(UInt64.MinValue, ByteVector.FromULong(UInt64.MinValue).ToULong());
     Assert.AreEqual(0, ByteVector.FromULong(0).ToULong());
     Assert.AreEqual(30292, ByteVector.FromULong(30292).ToULong());
 }
예제 #2
0
 public override void Save()
 {
     Mode = AccessMode.Write;
     try
     {
         long       original_tag_length = tag_end - tag_start;
         ByteVector data = new ByteVector();
         if (tag == null)
         {
             RemoveBlock(tag_start, original_tag_length);
             Insert(ByteVector.FromULong((ulong)(0), false), 20, 8);
         }
         else
         {
             data = tag.Render();
             if (tag_start == 0 || tag_end < tag_start)
             {
                 tag_start = tag_end = Length;
                 Insert(ByteVector.FromULong((ulong)(tag_start), false), 20, 8);
             }
             Insert(data, tag_start, data.Count);
         }
         long length = dsf_size + data.Count - original_tag_length;
         if (data.Count - original_tag_length != 0 && tag_start <= dsf_size)
         {
             Insert(ByteVector.FromULong((ulong)(length), false), 12, 8);
         }
         TagTypesOnDisk = TagTypes;
     }
     finally
     {
         Mode = AccessMode.Closed;
     }
 }
예제 #3
0
        /// <summary>
        ///    Renders the header represented by the current instance.
        /// </summary>
        /// <returns>
        ///    A <see cref="ByteVector" /> object containing the
        ///    rendered version of the current instance.
        /// </returns>
        public ByteVector Render()
        {
            // Enlarge for size if necessary.
            if ((header_size == 8 || header_size == 24) &&
                box_size > uint.MaxValue)
            {
                header_size += 8;
                box_size    += 8;
            }

            // Add the box size and type to the output.
            ByteVector output = ByteVector.FromUInt(
                (header_size == 8 || header_size == 24) ?
                (uint)box_size : 1);

            output.Add(box_type);

            // If the box size is 16 or 32, we must have more a
            // large header to append.
            if (header_size == 16 || header_size == 32)
            {
                output.Add(ByteVector.FromULong(box_size));
            }

            // The only reason for such a big size is an extended
            // type. Extend!!!
            if (header_size >= 24)
            {
                output.Add(extended_type);
            }

            return(output);
        }
예제 #4
0
        private ByteVector Render(bool isHeader)
        {
            ByteVector v = new ByteVector();

            v.Add(FileIdentifier);
            v.Add(ByteVector.FromUInt(2000, false));
            v.Add(ByteVector.FromUInt(tag_size, false));
            v.Add(ByteVector.FromUInt(item_count, false));
            uint flags = 0;

            if ((Flags & FooterFlags.HeaderPresent) != 0)
            {
                flags |= (uint)FooterFlags.HeaderPresent;
            }
            if (isHeader)
            {
                flags |= (uint)FooterFlags.IsHeader;
            }
            else
            {
                flags &= (uint)~FooterFlags.IsHeader;
            }
            v.Add(ByteVector.FromUInt(flags, false));
            v.Add(ByteVector.FromULong(0));
            return(v);
        }
예제 #5
0
        protected override ByteVector RenderFields(byte version)
        {
            ByteVector data = new ByteVector();

            data.Add(ByteVector.FromString(identification, StringType.Latin1));
            data.Add(ByteVector.TextDelimiter(StringType.Latin1));
            for (byte i = 0; i < 9; i++)
            {
                if (!channels[i].IsSet)
                {
                    continue;
                }
                data.Add(i);
                unchecked
                {
                    data.Add(ByteVector.FromUShort((ushort)channels[i].VolumeAdjustmentIndex));
                }
                byte bits = 0;
                for (byte j = 0; j < 64; j++)
                {
                    if ((channels[i].PeakVolumeIndex & (1UL << j)) != 0)
                    {
                        bits = (byte)(j + 1);
                    }
                }
                data.Add(bits);
                if (bits > 0)
                {
                    data.Add(ByteVector.FromULong(channels[i].PeakVolumeIndex).Mid(8 - BitsToBytes(bits)));
                }
            }
            return(data);
        }
예제 #6
0
        protected override ByteVector RenderFields(byte version)
        {
            ByteVector data = ByteVector.FromULong(play_count);

            while (data.Count > 4 && data[0] == 0)
            {
                data.RemoveAt(0);
            }
            return(data);
        }
예제 #7
0
        /// <summary>
        ///    Saves the changes made in the current instance to the
        ///    file it represents.
        /// </summary>
        public override void Save()
        {
            // Boilerplate
            PreSave();

            Mode = AccessMode.Write;
            try
            {
                long       original_tag_length = tag_end - tag_start;
                ByteVector data = new ByteVector();

                if (tag == null)
                {
                    // The tag has been removed
                    RemoveBlock(tag_start, original_tag_length);
                    Insert(ByteVector.FromULong((ulong)(0),
                                                false), 20, 8);
                }
                else
                {
                    data = tag.Render();

                    // If tagging info cannot be found, place it at
                    // the end of the file.
                    if (tag_start == 0 || tag_end < tag_start)
                    {
                        tag_start = tag_end = Length;
                        // Update the New Tag start
                        Insert(ByteVector.FromULong((ulong)(tag_start),
                                                    false), 20, 8);
                    }

                    // Insert the tagging data.
                    Insert(data, tag_start, data.Count);
                }

                long length = dsf_size + data.Count - original_tag_length;

                // If the data size changed update the dsf  size.
                if (data.Count - original_tag_length != 0 &&
                    tag_start <= dsf_size)
                {
                    Insert(ByteVector.FromULong((ulong)(length),
                                                false), 12, 8);
                }
                // Update the tag types.
                TagTypesOnDisk = TagTypes;
            }
            finally
            {
                Mode = AccessMode.Closed;
            }
        }
예제 #8
0
        protected override ByteVector RenderFields(byte version)
        {
            ByteVector data = ByteVector.FromULong(play_count);

            while (data.Count > 0 && data[0] == 0)
            {
                data.RemoveAt(0);
            }
            data.Insert(0, rating);
            data.Insert(0, 0);
            data.Insert(0, ByteVector.FromString(user, StringType.Latin1));
            return(data);
        }
		public void OperatorAdd ()
		{
			using (new CodeTimer ("Operator Add")) {
				var vector = new ByteVector ();
				for (int i = 0; i < 10000; i++) {
					vector += ByteVector.FromULong (55);
				}
			}

			using (new CodeTimer ("Function Add")) {
				var vector = new ByteVector ();
				for (int i = 0; i < 10000; i++) {
					vector.Add (ByteVector.FromULong (55));
				}
			}
		}
예제 #10
0
        public ByteVector Render()
        {
            ByteVector data = new ByteVector();

            data.Add("OggS");
            data.Add(version);
            data.Add((byte)flags);
            data.Add(ByteVector.FromULong(absolute_granular_position, false));
            data.Add(ByteVector.FromUInt(stream_serial_number, false));
            data.Add(ByteVector.FromUInt((uint)page_sequence_number, false));
            data.Add(new ByteVector(4, 0));
            ByteVector page_segments = LacingValues;

            data.Add((byte)page_segments.Count);
            data.Add(page_segments);
            return(data);
        }
예제 #11
0
        public ByteVector Render()
        {
            ByteVector data = new ByteVector();

            data.Add("OggS");
            data.Add(_version); // stream structure version
            data.Add((byte)_flags);
            data.Add(ByteVector.FromULong(_absolute_granular_position, false));
            data.Add(ByteVector.FromUInt(_stream_serial_number, false));
            data.Add(ByteVector.FromUInt((uint)_page_sequence_number, false));
            data.Add(new ByteVector(4, 0)); // checksum, to be filled in later.
            ByteVector page_segments = LacingValues;

            data.Add((byte)page_segments.Count);
            data.Add(page_segments);

            return(data);
        }
예제 #12
0
        /// <summary>
        ///     Renders the current instance as either an APE tag header
        ///     or footer.
        /// </summary>
        /// <param name="isHeader">
        ///     A <see cref="bool" /> value indicating whether or not the
        ///     current instance is to be rendered as a header.
        /// </param>
        /// <returns>
        ///     A <see cref="ByteVector" /> object containing the
        ///     rendered version of the current instance.
        /// </returns>
        private ByteVector Render(bool isHeader)
        {
            var v = new ByteVector
            {
                // add the file identifier -- "APETAGEX"
                FileIdentifier,

                // add the version number -- we always render a 2.000
                // tag regardless of what the tag originally was.
                ByteVector.FromUInt(2000, false),

                // add the tag size
                ByteVector.FromUInt(TagSize, false),

                // add the item count
                ByteVector.FromUInt(ItemCount, false)
            };

            // render and add the flags
            uint flags = 0;

            if ((Flags & FooterFlags.HeaderPresent) != 0)
            {
                flags |= (uint)FooterFlags.HeaderPresent;
            }

            // footer is always present
            if (isHeader)
            {
                flags |= (uint)FooterFlags.IsHeader;
            }
            else
            {
                flags &= (uint)~FooterFlags.IsHeader;
            }

            v.Add(ByteVector.FromUInt(flags, false));

            // add the reserved 64bit
            v.Add(ByteVector.FromULong(0));

            return(v);
        }
예제 #13
0
        public ByteVector Render()
        {
            if ((header_size == 8 || header_size == 24) && box_size > uint.MaxValue)
            {
                header_size += 8;
                box_size    += 8;
            }
            ByteVector output = ByteVector.FromUInt((header_size == 8 || header_size == 24)?(uint)box_size:1);

            output.Add(box_type);
            if (header_size == 16 || header_size == 32)
            {
                output.Add(ByteVector.FromULong(box_size));
            }
            if (header_size >= 24)
            {
                output.Add(extended_type);
            }
            return(output);
        }
예제 #14
0
        /// <summary>
        ///    Renders the current instance as a raw Ogg page header.
        /// </summary>
        /// <returns>
        ///    A <see cref="ByteVector" /> object containing the
        ///    rendered version of the current instance.
        /// </returns>
        public ByteVector Render()
        {
            ByteVector data = new ByteVector {
                "OggS",
                version,                 // stream structure version
                (byte)Flags,
                ByteVector.FromULong(
                    absolute_granular_position, false),
                ByteVector.FromUInt(
                    StreamSerialNumber, false),
                ByteVector.FromUInt(
                    PageSequenceNumber, false),
                new ByteVector(4, 0)                  // checksum, to be filled in later.
            };
            ByteVector page_segments = LacingValues;

            data.Add((byte)page_segments.Count);
            data.Add(page_segments);

            return(data);
        }
예제 #15
0
 /// <summary>
 ///    Renders a 8-byte QWORD.
 /// </summary>
 /// <param name="value">
 ///    A <see cref="ulong" /> value containing the QWORD to
 ///    render.
 /// </param>
 /// <returns>
 ///    A <see cref="ByteVector" /> object containing the
 ///    rendered value.
 /// </returns>
 public static ByteVector RenderQWord(ulong value)
 {
     return(ByteVector.FromULong(value, false));
 }