public void Write(Stream stream, IPListElement element)
 {
   this.BaseStream = stream;
   this.Offsets = new List<int>();
   this.BaseStream.Write(PListBinaryWriter.s_PListHeader, 0, PListBinaryWriter.s_PListHeader.Length);
   int plistElementCount = element.GetPListElementCount();
   this.ElementIdxSize = plistElementCount > (int) byte.MaxValue ? (plistElementCount > (int) short.MaxValue ? (byte) 4 : (byte) 2) : (byte) 1;
   int host = this.WriteInternal(element);
   int count = this.Offsets.Count;
   int position = (int) this.BaseStream.Position;
   byte num = position > (int) byte.MaxValue ? (position > (int) short.MaxValue ? (byte) 4 : (byte) 2) : (byte) 1;
   for (int index = 0; index < this.Offsets.Count; ++index)
   {
     byte[] buffer = (byte[]) null;
     switch (num)
     {
       case 1:
         buffer = new byte[1]
         {
           (byte) this.Offsets[index]
         };
         break;
       case 2:
         buffer = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((short) this.Offsets[index]));
         break;
       case 4:
         buffer = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(this.Offsets[index]));
         break;
     }
     this.BaseStream.Write(buffer, 0, buffer.Length);
   }
   byte[] buffer1 = new byte[32];
   buffer1[6] = num;
   buffer1[7] = this.ElementIdxSize;
   BitConverter.GetBytes(IPAddress.HostToNetworkOrder(count)).CopyTo((Array) buffer1, 12);
   BitConverter.GetBytes(IPAddress.HostToNetworkOrder(host)).CopyTo((Array) buffer1, 20);
   BitConverter.GetBytes(IPAddress.HostToNetworkOrder(position)).CopyTo((Array) buffer1, 28);
   this.BaseStream.Write(buffer1, 0, buffer1.Length);
 }
        /// <summary>
        /// Writers a <see cref="T:CE.iPhone.IPListElemnet"/> to the specified stream.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="element">The element.</param>
        public void Write(Stream stream, IPListElement element)
        {
            BaseStream = stream;
            Offsets = new List<int>();
            BaseStream.Write(s_PListHeader, 0, s_PListHeader.Length);
            int elemCnt = element.GetPListElementCount();
            if (elemCnt <= Byte.MaxValue) ElementIdxSize = sizeof(Byte);
            else if (elemCnt <= Int16.MaxValue) ElementIdxSize = sizeof(Int16);
            else ElementIdxSize = sizeof(Int32);

            int topOffestIdx = WriteInternal(element);
            elemCnt = Offsets.Count;

            int offsetTableOffset = (int)BaseStream.Position;

            Byte offsetSize = 0;
            if (offsetTableOffset <= Byte.MaxValue) offsetSize = sizeof(Byte);
            else if (offsetTableOffset <= Int16.MaxValue) offsetSize = sizeof(Int16);
            else offsetSize = sizeof(Int32);

            for (int i = 0; i < Offsets.Count; i++) {
                Byte[] buf = null;
                switch (offsetSize) {
                    case 1: buf = new Byte[] { (Byte)Offsets[i] }; break;
                    case 2: buf = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((Int16)Offsets[i])); break;
                    case 4: buf = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((Int32)Offsets[i])); break;
                }
                BaseStream.Write(buf, 0, buf.Length);
            }

            //BaseStream.Write(s_PListHeader, 0, s_PListHeader.Length);

            Byte[] header = new Byte[32];
            header[6] = offsetSize;
            header[7] = ElementIdxSize;

            BitConverter.GetBytes(IPAddress.HostToNetworkOrder(elemCnt)).CopyTo(header, 12);
            BitConverter.GetBytes(IPAddress.HostToNetworkOrder(topOffestIdx)).CopyTo(header, 20);
            BitConverter.GetBytes(IPAddress.HostToNetworkOrder(offsetTableOffset)).CopyTo(header, 28);

            BaseStream.Write(header, 0, header.Length);
        }
Beispiel #3
0
        /// <summary>
        /// Writers a <see cref="T:CE.iPhone.IPListElemnet"/> to the specified stream.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="element">The element.</param>
        public void Write(Stream stream, IPListElement element)
        {
            BaseStream = stream;
            Offsets    = new List <int>();
            BaseStream.Write(s_PListHeader, 0, s_PListHeader.Length);
            int elemCnt = element.GetPListElementCount();

            if (elemCnt <= Byte.MaxValue)
            {
                ElementIdxSize = sizeof(Byte);
            }
            else if (elemCnt <= Int16.MaxValue)
            {
                ElementIdxSize = sizeof(Int16);
            }
            else
            {
                ElementIdxSize = sizeof(Int32);
            }

            int topOffestIdx = WriteInternal(element);

            elemCnt = Offsets.Count;

            int offsetTableOffset = (int)BaseStream.Position;


            Byte offsetSize = 0;

            if (offsetTableOffset <= Byte.MaxValue)
            {
                offsetSize = sizeof(Byte);
            }
            else if (offsetTableOffset <= Int16.MaxValue)
            {
                offsetSize = sizeof(Int16);
            }
            else
            {
                offsetSize = sizeof(Int32);
            }

            for (int i = 0; i < Offsets.Count; i++)
            {
                Byte[] buf = null;
                switch (offsetSize)
                {
                case 1: buf = new Byte[] { (Byte)Offsets[i] }; break;

                case 2: buf = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((Int16)Offsets[i])); break;

                case 4: buf = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((Int32)Offsets[i])); break;
                }
                BaseStream.Write(buf, 0, buf.Length);
            }


            //BaseStream.Write(s_PListHeader, 0, s_PListHeader.Length);

            Byte[] header = new Byte[32];
            header[6] = offsetSize;
            header[7] = ElementIdxSize;

            BitConverter.GetBytes(IPAddress.HostToNetworkOrder(elemCnt)).CopyTo(header, 12);
            BitConverter.GetBytes(IPAddress.HostToNetworkOrder(topOffestIdx)).CopyTo(header, 20);
            BitConverter.GetBytes(IPAddress.HostToNetworkOrder(offsetTableOffset)).CopyTo(header, 28);

            BaseStream.Write(header, 0, header.Length);
        }