예제 #1
0
        internal override void ToBinary(BinaryPropertyListWriter outPlist)
        {
            outPlist.Write(0x80 + ByteCount - 1);
            Span <byte> bytes = stackalloc byte[ByteCount];

            GetBytes(bytes);
            outPlist.Write(bytes);
        }
예제 #2
0
        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);
        }
예제 #3
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);
        }
예제 #4
0
 /// <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);
 }
예제 #5
0
        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;
            }
            }
        }
예제 #6
0
파일: NSData.cs 프로젝트: admsrv/plist-cil
 internal override void ToBinary(BinaryPropertyListWriter outPlist)
 {
     outPlist.WriteIntHeader(0x4, bytes.Length);
     outPlist.Write(bytes);
 }
예제 #7
0
 internal override void ToBinary(BinaryPropertyListWriter outPlist)
 {
     outPlist.WriteIntHeader(0x4, bytes.Length);
     outPlist.Write(bytes);
 }
예제 #8
0
 internal override void ToBinary(BinaryPropertyListWriter outPlist)
 {
     outPlist.Write(0x80 + bytes.Length - 1);
     outPlist.Write(bytes);
 }
예제 #9
0
 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;
             }
     }
 }
예제 #10
0
        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);
        }
예제 #11
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);
 }
 /// <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);
 }
예제 #13
0
 internal override void ToBinary(BinaryPropertyListWriter outPlist)
 {
     outPlist.Write(0x33);
     outPlist.WriteDouble((date - EPOCH).TotalSeconds);
 }
예제 #14
0
 internal override void ToBinary(BinaryPropertyListWriter outPlist)
 {
     outPlist.Write(0x33);
     outPlist.WriteDouble((date - EPOCH).TotalSeconds);
 }
예제 #15
0
파일: UID.cs 프로젝트: quamotion/plist-cil
 internal override void ToBinary(BinaryPropertyListWriter outPlist)
 {
     outPlist.Write(0x80 + bytes.Length - 1);
     outPlist.Write(bytes);
 }