Пример #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 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;
        }