示例#1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="Claunia.PropertyList.UID" /> class.
        /// </summary>
        /// <param name="bytes">Bytes.</param>
        public UID(ReadOnlySpan <byte> bytes)
        {
            if (bytes.Length != 1 && bytes.Length != 2 && bytes.Length != 4 && bytes.Length != 8)
            {
                throw new ArgumentException("Type argument is not valid.");
            }

            value = (ulong)BinaryPropertyListParser.ParseLong(bytes);
        }
示例#2
0
        /// <summary>
        ///     Parses a property list from a byte span.
        /// </summary>
        /// <param name="bytes">The property list data as a byte array.</param>
        /// <returns>The root object in the property list. This is usually a NSDictionary but can also be a NSArray.</returns>
        public static NSObject Parse(ReadOnlySpan <byte> bytes)
        {
            switch (DetermineType(bytes))
            {
            case TYPE_BINARY: return(BinaryPropertyListParser.Parse(bytes));

            case TYPE_XML:    return(XmlPropertyListParser.Parse(bytes.ToArray()));

            case TYPE_ASCII:  return(ASCIIPropertyListParser.Parse(bytes));

            default:
                throw new
                      PropertyListFormatException("The given data is not a property list of a supported format.");
            }
        }
示例#3
0
        /// <summary>
        /// Parses integers and real numbers from their binary representation.
        /// <i>Note: real numbers are not yet supported.</i>
        /// </summary>
        /// <param name="bytes">The binary representation</param>
        /// <param name="type">The type of number</param>
        /// <seealso cref="INTEGER"/>
        /// <seealso cref="REAL"/>
        public NSNumber(byte[] bytes, int type)
        {
            switch (type)
            {
            case INTEGER:
                doubleValue = longValue = BinaryPropertyListParser.ParseLong(bytes);
                break;

            case REAL:
                doubleValue = BinaryPropertyListParser.ParseDouble(bytes);
                longValue   = (long)Math.Round(doubleValue);
                break;

            default:
                throw new ArgumentException("Type argument is not valid.");
            }
            this.type = type;
        }
示例#4
0
        /// <summary>
        /// Parses a property list from a file.
        /// </summary>
        /// <param name="f">The property list file.</param>
        /// <returns>The root object in the property list. This is usually a NSDictionary but can also be a NSArray.</returns>
        public static NSObject Parse(FileInfo f)
        {
            int type;

            using (FileStream fis = f.OpenRead())
            {
                type = DetermineType(fis);
            }

            switch (type)
            {
            case TYPE_BINARY:
                return(BinaryPropertyListParser.Parse(f));

            case TYPE_XML:
                return(XmlPropertyListParser.Parse(f));

            case TYPE_ASCII:
                return(ASCIIPropertyListParser.Parse(f));

            default:
                throw new PropertyListFormatException("The given file is not a property list of a supported format.");
            }
        }
示例#5
0
        /// <summary>
        ///     Parses a binary property list from a byte span.
        /// </summary>
        /// <param name="data">The binary property list's data.</param>
        /// <returns>The root object of the property list. This is usually a NSDictionary but can also be a NSArray.</returns>
        /// <exception cref="PropertyListFormatException">When the property list's format could not be parsed.</exception>
        public static NSObject Parse(ReadOnlySpan <byte> data)
        {
            BinaryPropertyListParser parser = new BinaryPropertyListParser();

            return(parser.DoParse(data));
        }
 /// <summary>
 /// Parses a binary property list from a byte array.
 /// </summary>
 /// <param name="data">The binary property list's data.</param>
 /// <returns>The root object of the property list. This is usually a NSDictionary but can also be a NSArray.</returns>
 /// <exception cref="PropertyListFormatException">When the property list's format could not be parsed.</exception>
 public static NSObject Parse(byte[] data)
 {
     BinaryPropertyListParser parser = new BinaryPropertyListParser();
     return parser.DoParse(data);
 }
        /// <summary>
        /// Parses a binary property list from a byte array.
        /// </summary>
        /// <param name="data">The binary property list's data.</param>
        /// <returns>The root object of the property list. This is usually a NSDictionary but can also be a NSArray.</returns>
        /// <exception cref="PropertyListFormatException">When the property list's format could not be parsed.</exception>
        public static NSObject Parse(byte[] data)
        {
            BinaryPropertyListParser parser = new BinaryPropertyListParser();

            return(parser.DoParse(data));
        }
示例#8
0
 /// <summary>
 /// Creates a date from its binary representation.
 /// </summary>
 /// <param name="bytes">bytes The date bytes</param>
 public NSDate(byte[] bytes)
 {
     //dates are 8 byte big-endian double, seconds since the epoch
     date = EPOCH.AddSeconds(BinaryPropertyListParser.ParseDouble(bytes));
 }
示例#9
0
 /// <summary>
 /// Creates a date from its binary representation.
 /// </summary>
 /// <param name="bytes">bytes The date bytes</param>
 public NSDate(byte[] bytes, INsOrigin origin = null) : base(origin)
 {
     //dates are 8 byte big-endian double, seconds since the epoch
     date = EPOCH.AddSeconds(BinaryPropertyListParser.ParseDouble(bytes));
 }