示例#1
0
        /// <summary>
        /// Adds an array to the internal object table.
        /// </summary>
        /// <param name="value">The value to add.</param>
        /// <returns>The index of the added value.</returns>
        private int AddArray(IEnumerable value)
        {
            int index = this.objectTable.Count;

            BinaryPlistArray array = new BinaryPlistArray(this.objectTable);
            BinaryPlistItem  item  = new BinaryPlistItem(array);

            item.IsArray = true;
            this.objectTable.Add(item);

            foreach (object obj in value)
            {
                array.ObjectReference.Add(this.AddObject(obj));
                this.objectRefCount++;
            }

            if (array.ObjectReference.Count < 15)
            {
                item.Marker.Add((byte)((byte)0xA0 | (byte)array.ObjectReference.Count));
            }
            else
            {
                item.Marker.Add((byte)0xAF);
                AddIntegerCount(item.Marker, array.ObjectReference.Count);
            }

            this.objectTableSize += item.Size;
            return(index);
        }
        /// <summary>
        /// Reads an array value from the given reader, starting at the given index and of the given size.
        /// </summary>
        /// <param name="reader">The <see cref="BinaryReader"/> to read the array value from.</param>
        /// <param name="index">The index in the stream the array value starts at.</param>
        /// <param name="size">The number of items in the array.</param>
        /// <returns>An array value.</returns>
        private BinaryPlistArray ReadArray(BinaryReader reader, long index, int size)
        {
            BinaryPlistArray array = new BinaryPlistArray(this.objectTable, size);

            for (int i = 0; i < size; i++)
            {
                array.ObjectReference.Add((int)ReadInteger(reader, index + (i * this.objectRefSize), this.objectRefSize));
            }

            return(array);
        }
示例#3
0
        /// <summary>
        /// Writes an array item to the given <see cref="BinaryWriter"/>.
        /// </summary>
        /// <param name="writer">The <see cref="BinaryWriter"/> to write to.</param>
        /// <param name="value">The array item to write.</param>
        /// <returns>The number of bytes written.</returns>
        private int WriteArray(BinaryWriter writer, BinaryPlistItem value)
        {
            int size = value.Marker.Count;
            BinaryPlistArray array = (BinaryPlistArray)value.Value;

            writer.Write(value.Marker.ToArray());

            foreach (int objectRef in array.ObjectReference)
            {
                size += WriteReferenceInteger(writer, objectRef, this.objectRefSize);
            }

            return(size);
        }
        /// <summary>
        /// Adds an array to the internal object table.
        /// </summary>
        /// <param name="value">The value to add.</param>
        /// <returns>The index of the added value.</returns>
        private int AddArray(IEnumerable value)
        {
            int index = this.objectTable.Count;

            BinaryPlistArray array = new BinaryPlistArray(this.objectTable);
            BinaryPlistItem item = new BinaryPlistItem(array);
            item.IsArray = true;
            this.objectTable.Add(item);

            foreach (object obj in value)
            {
                array.ObjectReference.Add(this.AddObject(obj));
                this.objectRefCount++;
            }

            if (array.ObjectReference.Count < 15)
            {
                item.Marker.Add((byte)((byte)0xA0 | (byte)array.ObjectReference.Count));
            }
            else
            {
                item.Marker.Add((byte)0xAF);
                AddIntegerCount(item.Marker, array.ObjectReference.Count);
            }

            this.objectTableSize += item.Size;
            return index;
        }