internal override void ToBinary(BinaryPropertyListWriter outPlist)
        {
            int kind;

            byte[] byteBuf;
            lock (typeof(NSString)) {
                if (asciiEncoder == null)
                {
                    // Not much use, because some characters do not fallback to exception, even if not ASCII
                    asciiEncoder = Encoding.GetEncoding("ascii", EncoderFallback.ExceptionFallback, DecoderFallback.ExceptionFallback);
                }

                if (IsASCIIEncodable(content))
                {
                    kind    = 0x5;                  // standard ASCII
                    byteBuf = asciiEncoder.GetBytes(content);
                }
                else
                {
                    if (utf16beEncoder == null)
                    {
                        utf16beEncoder = Encoding.BigEndianUnicode;
                    }

                    kind    = 0x6;                  // UTF-16-BE
                    byteBuf = utf16beEncoder.GetBytes(content);
                }
            }
            outPlist.WriteIntHeader(kind, content.Length);
            outPlist.Write(byteBuf);
        }
Exemple #2
0
 internal override void AssignIDs(BinaryPropertyListWriter outPlist)
 {
     base.AssignIDs(outPlist);
     foreach (NSObject obj in set)
     {
         obj.AssignIDs(outPlist);
     }
 }
Exemple #3
0
 internal override void ToBinary(BinaryPropertyListWriter outPlist)
 {
     outPlist.WriteIntHeader(0xA, array.Count);
     foreach (NSObject obj in array)
     {
         outPlist.WriteID(outPlist.GetID(obj));
     }
 }
Exemple #4
0
        /// <summary>
        /// Saves a property list with the given object as root into a binary file.
        /// </summary>
        /// <param name="root">The root object.</param>
        /// <param name="outFile">The output file.</param>
        /// <exception cref="IOException">When an error occurs during the writing process.</exception>
        public static void SaveAsBinary(NSObject root, FileInfo outFile)
        {
            string parent = outFile.DirectoryName;

            if (!Directory.Exists(parent))
            {
                Directory.CreateDirectory(parent);
            }
            BinaryPropertyListWriter.Write(outFile, root);
        }
 internal override void ToBinary(BinaryPropertyListWriter outPlist)
 {
     outPlist.WriteIntHeader(0xD, dict.Count);
     foreach (KeyValuePair <String, NSObject> entry in dict)
     {
         outPlist.WriteID(outPlist.GetID(new NSString(entry.Key)));
     }
     foreach (KeyValuePair <String, NSObject> entry in dict)
     {
         outPlist.WriteID(outPlist.GetID(entry.Value));
     }
 }
        /// <summary>
        /// Writes a binary plist serialization of the given object as the root.
        /// </summary>
        /// <param name="outStream">the stream to write to</param>
        /// <param name="root">the source of the data to write to the stream</param>
        /// <exception cref="IOException"></exception>
        public static void Write(Stream outStream, NSObject root)
        {
            int minVersion = GetMinimumRequiredVersion(root);

            if (minVersion > VERSION_00)
            {
                string versionString = ((minVersion == VERSION_10) ? "v1.0" : ((minVersion == VERSION_15) ? "v1.5" : ((minVersion == VERSION_20) ? "v2.0" : "v0.0")));
                throw new IOException("The given property list structure cannot be saved. " +
                                      "The required version of the binary format (" + versionString + ") is not yet supported.");
            }
            BinaryPropertyListWriter w = new BinaryPropertyListWriter(outStream, minVersion);

            w.Write(root);
        }
        internal override void AssignIDs(BinaryPropertyListWriter outPlist)
        {
            base.AssignIDs(outPlist);

            foreach (KeyValuePair <string, NSObject> entry in dict)
            {
                new NSString(entry.Key).AssignIDs(outPlist);
            }

            foreach (KeyValuePair <string, NSObject> entry in dict)
            {
                entry.Value.AssignIDs(outPlist);
            }
        }
Exemple #8
0
 internal override void ToBinary(BinaryPropertyListWriter outPlist)
 {
     if (ordered)
     {
         set.Sort();
         outPlist.WriteIntHeader(0xB, set.Count);
     }
     else
     {
         outPlist.WriteIntHeader(0xC, set.Count);
     }
     foreach (NSObject obj in set)
     {
         outPlist.WriteID(outPlist.GetID(obj));
     }
 }
        internal override void ToBinary(BinaryPropertyListWriter outPlist)
        {
            switch (GetNSNumberType())
            {
            case INTEGER: {
                if (ToLong() < 0)
                {
                    outPlist.Write(0x13);
                    outPlist.WriteBytes(ToLong(), 8);
                }
                else if (ToLong() <= 0xff)
                {
                    outPlist.Write(0x10);
                    outPlist.WriteBytes(ToLong(), 1);
                }
                else if (ToLong() <= 0xffff)
                {
                    outPlist.Write(0x11);
                    outPlist.WriteBytes(ToLong(), 2);
                }
                else if (ToLong() <= 0xffffffffL)
                {
                    outPlist.Write(0x12);
                    outPlist.WriteBytes(ToLong(), 4);
                }
                else
                {
                    outPlist.Write(0x13);
                    outPlist.WriteBytes(ToLong(), 8);
                }
                break;
            }

            case REAL: {
                outPlist.Write(0x23);
                outPlist.WriteDouble(ToDouble());
                break;
            }

            case BOOLEAN: {
                outPlist.Write(ToBool() ? 0x09 : 0x08);
                break;
            }
            }
        }
Exemple #10
0
 /// <summary>
 /// Generates the binary representation of the object.
 /// </summary>
 /// <param name="outPlist">The output stream to serialize the object to.</param>
 internal abstract void ToBinary(BinaryPropertyListWriter outPlist);
Exemple #11
0
 /// <summary>
 /// Assigns IDs to all the objects in this NSObject subtree.
 /// </summary>
 /// <param name="outPlist">The writer object that handles the binary serialization.</param>
 internal virtual void AssignIDs(BinaryPropertyListWriter outPlist)
 {
     outPlist.AssignID(this);
 }
Exemple #12
0
 /// <summary>
 /// Saves a property list with the given object as root in binary format into an output stream.
 /// </summary>
 /// <param name="root">The root object.</param>
 /// <param name="outStream">The output stream.</param>
 /// <exception cref="IOException">When an error occurs during the writing process.</exception>
 public static void SaveAsBinary(NSObject root, Stream outStream)
 {
     BinaryPropertyListWriter.Write(outStream, root);
 }
Exemple #13
0
 internal override void ToBinary(BinaryPropertyListWriter outPlist)
 {
     outPlist.Write(0x33);
     outPlist.WriteDouble((date - EPOCH).TotalSeconds);
 }
Exemple #14
0
 internal override void ToBinary(BinaryPropertyListWriter outPlist)
 {
     outPlist.WriteIntHeader(0x4, bytes.Length);
     outPlist.Write(bytes);
 }
Exemple #15
0
 internal override void ToBinary(BinaryPropertyListWriter outPlist)
 {
     outPlist.Write(0x80 + bytes.Length - 1);
     outPlist.Write(bytes);
 }