SetByteValue() public méthode

Sets the ByteValue to the given collection.
public SetByteValue ( IEnumerable buffer ) : void
buffer IEnumerable The collection to set.
Résultat void
Exemple #1
0
        /// <summary>
        /// Adds a float to the internal object table.
        /// </summary>
        /// <param name="value">The value to add.</param>
        /// <returns>The index of the added value.</returns>
        private int AddFloat(float value)
        {
            if (!this.uniques.Contains(value))
            {
                int    index  = this.objectTable.Count;
                byte[] buffer = BitConverter.GetBytes(value);

                if (BitConverter.IsLittleEndian)
                {
                    Array.Reverse(buffer);
                }

                BinaryPlistItem item = new BinaryPlistItem(value);
                item.Marker.Add((byte)((byte)0x20 | (byte)Math.Log(buffer.Length, 2)));
                item.SetByteValue(buffer);

                this.objectTable.Add(item);
                this.objectTableSize += item.Size;

                this.uniques.SetIndex(value, index);
                return(index);
            }

            return(this.uniques.GetIndex(value));
        }
Exemple #2
0
        /// <summary>
        /// Adds a date to the internal object table.
        /// </summary>
        /// <param name="value">The value to add.</param>
        /// <returns>The index of the added value.</returns>
        private int AddDate(DateTime value)
        {
            if (!this.uniques.Contains(value))
            {
                int    index  = this.objectTable.Count;
                byte[] buffer = BitConverter.GetBytes(value.ToUniversalTime().Subtract(ReferenceDate).TotalSeconds);

                if (BitConverter.IsLittleEndian)
                {
                    Array.Reverse(buffer);
                }

                BinaryPlistItem item = new BinaryPlistItem(value);
                item.Marker.Add((byte)0x33);
                item.SetByteValue(buffer);

                this.objectTable.Add(item);
                this.objectTableSize += item.Size;

                this.uniques.SetIndex(value, index);
                return(index);
            }

            return(this.uniques.GetIndex(value));
        }
Exemple #3
0
        /// <summary>
        /// Adds a string to the internal object table.
        /// </summary>
        /// <param name="value">The value to add.</param>
        /// <returns>The index of the added value.</returns>
        private int AddString(string value)
        {
            if (!this.uniques.Contains(value))
            {
                int    index = this.objectTable.Count;
                bool   ascii = value.IsAscii();
                byte[] buffer;

                BinaryPlistItem item = new BinaryPlistItem(value);

                if (value.Length < 15)
                {
                    item.Marker.Add((byte)((byte)(ascii ? 0x50 : 0x60) | (byte)value.Length));
                }
                else
                {
                    item.Marker.Add((byte)(ascii ? 0x5F : 0x6F));
                    AddIntegerCount(item.Marker, value.Length);
                }

                if (ascii)
                {
                    buffer = Encoding.ASCII.GetBytes(value);
                }
                else
                {
                    buffer = Encoding.Unicode.GetBytes(value);

                    if (BitConverter.IsLittleEndian)
                    {
                        for (int i = 0; i < buffer.Length; i++)
                        {
                            byte l = buffer[i];
                            buffer[i] = buffer[++i];
                            buffer[i] = l;
                        }
                    }
                }

                item.SetByteValue(buffer);

                this.objectTable.Add(item);
                this.objectTableSize += item.Size;

                this.uniques.SetIndex(value, index);
                return(index);
            }

            return(this.uniques.GetIndex(value));
        }
Exemple #4
0
        /// <summary>
        /// Adds an integer to the internal object table.
        /// </summary>
        /// <param name="value">The value to add.</param>
        /// <returns>The index of the added value.</returns>
        private int AddInteger(long value)
        {
            if (!this.uniques.Contains(value))
            {
                int index = this.objectTable.Count;

                BinaryPlistItem item = new BinaryPlistItem(value);
                item.SetByteValue(GetIntegerBytes(value));
                item.Marker.Add((byte)((byte)0x10 | (byte)Math.Log(item.ByteValue.Count, 2)));

                this.objectTable.Add(item);
                this.objectTableSize += item.Size;

                this.uniques.SetIndex(value, index);
                return(index);
            }

            return(this.uniques.GetIndex(value));
        }
Exemple #5
0
        /// <summary>
        /// Adds arbitrary data to the internal object table.
        /// </summary>
        /// <param name="value">The value to add.</param>
        /// <returns>The index of the added value.</returns>
        private int AddData(object value)
        {
            int index = this.objectTable.Count, count = 0, bufferIndex = 0;

            byte[] buffer = value as byte[];

            if (buffer == null)
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(stream, value);

                    stream.Position = 0;
                    buffer          = new byte[stream.Length];

                    while (0 < (count = stream.Read(buffer, 0, buffer.Length - bufferIndex)))
                    {
                        bufferIndex += count;
                    }
                }
            }

            BinaryPlistItem item = new BinaryPlistItem(value);

            item.SetByteValue(buffer);

            if (buffer.Length < 15)
            {
                item.Marker.Add((byte)((byte)0x40 | (byte)buffer.Length));
            }
            else
            {
                item.Marker.Add(0x4F);
                AddIntegerCount(item.Marker, buffer.Length);
            }

            this.objectTable.Add(item);
            this.objectTableSize += item.Size;

            return(index);
        }
        /// <summary>
        /// Adds a string to the internal object table.
        /// </summary>
        /// <param name="value">The value to add.</param>
        /// <returns>The index of the added value.</returns>
        private int AddString(string value)
        {
            if (!this.uniques.Contains(value))
            {
                int index = this.objectTable.Count;
                bool ascii = value.IsAscii();
                byte[] buffer;

                BinaryPlistItem item = new BinaryPlistItem(value);

                if (value.Length < 15)
                {
                    item.Marker.Add((byte)((byte)(ascii ? 0x50 : 0x60) | (byte)value.Length));
                }
                else
                {
                    item.Marker.Add((byte)(ascii ? 0x5F : 0x6F));
                    AddIntegerCount(item.Marker, value.Length);
                }

                if (ascii)
                {
                    buffer = Encoding.ASCII.GetBytes(value);
                }
                else
                {
                    buffer = Encoding.Unicode.GetBytes(value);

                    if (BitConverter.IsLittleEndian)
                    {
                        for (int i = 0; i < buffer.Length; i++)
                        {
                            byte l = buffer[i];
                            buffer[i] = buffer[++i];
                            buffer[i] = l;
                        }
                    }
                }

                item.SetByteValue(buffer);

                this.objectTable.Add(item);
                this.objectTableSize += item.Size;

                this.uniques.SetIndex(value, index);
                return index;
            }

            return this.uniques.GetIndex(value);
        }
        /// <summary>
        /// Adds an integer to the internal object table.
        /// </summary>
        /// <param name="value">The value to add.</param>
        /// <returns>The index of the added value.</returns>
        private int AddInteger(long value)
        {
            if (!this.uniques.Contains(value))
            {
                int index = this.objectTable.Count;

                BinaryPlistItem item = new BinaryPlistItem(value);
                item.SetByteValue(GetIntegerBytes(value));
                item.Marker.Add((byte)((byte)0x10 | (byte)Math.Log(item.ByteValue.Count, 2)));

                this.objectTable.Add(item);
                this.objectTableSize += item.Size;

                this.uniques.SetIndex(value, index);
                return index;
            }

            return this.uniques.GetIndex(value);
        }
        /// <summary>
        /// Adds a float to the internal object table.
        /// </summary>
        /// <param name="value">The value to add.</param>
        /// <returns>The index of the added value.</returns>
        private int AddFloat(float value)
        {
            if (!this.uniques.Contains(value))
            {
                int index = this.objectTable.Count;
                byte[] buffer = BitConverter.GetBytes(value);

                if (BitConverter.IsLittleEndian)
                {
                    Array.Reverse(buffer);
                }

                BinaryPlistItem item = new BinaryPlistItem(value);
                item.Marker.Add((byte)((byte)0x20 | (byte)Math.Log(buffer.Length, 2)));
                item.SetByteValue(buffer);

                this.objectTable.Add(item);
                this.objectTableSize += item.Size;

                this.uniques.SetIndex(value, index);
                return index;
            }

            return this.uniques.GetIndex(value);
        }
        /// <summary>
        /// Adds a date to the internal object table.
        /// </summary>
        /// <param name="value">The value to add.</param>
        /// <returns>The index of the added value.</returns>
        private int AddDate(DateTime value)
        {
            if (!this.uniques.Contains(value))
            {
                int index = this.objectTable.Count;
                byte[] buffer = BitConverter.GetBytes(value.ToUniversalTime().Subtract(ReferenceDate).TotalSeconds);

                if (BitConverter.IsLittleEndian)
                {
                    Array.Reverse(buffer);
                }

                BinaryPlistItem item = new BinaryPlistItem(value);
                item.Marker.Add((byte)0x33);
                item.SetByteValue(buffer);

                this.objectTable.Add(item);
                this.objectTableSize += item.Size;

                this.uniques.SetIndex(value, index);
                return index;
            }

            return this.uniques.GetIndex(value);
        }
        /// <summary>
        /// Adds arbitrary data to the internal object table.
        /// </summary>
        /// <param name="value">The value to add.</param>
        /// <returns>The index of the added value.</returns>
        private int AddData(object value)
        {
            int index = this.objectTable.Count, count = 0, bufferIndex = 0;
            byte[] buffer = value as byte[];

            if (buffer == null)
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(stream, value);

                    stream.Position = 0;
                    buffer = new byte[stream.Length];

                    while (0 < (count = stream.Read(buffer, 0, buffer.Length - bufferIndex)))
                    {
                        bufferIndex += count;
                    }
                }
            }

            BinaryPlistItem item = new BinaryPlistItem(value);
            item.SetByteValue(buffer);

            if (buffer.Length < 15)
            {
                item.Marker.Add((byte)((byte)0x40 | (byte)buffer.Length));
            }
            else
            {
                item.Marker.Add(0x4F);
                AddIntegerCount(item.Marker, buffer.Length);
            }

            this.objectTable.Add(item);
            this.objectTableSize += item.Size;

            return index;
        }