Example #1
0
        /// <summary>
        /// Deserializes an object from a binary source.
        /// </summary>
        /// <param name="Reader">Deserializer.</param>
        /// <param name="DataType">Optional datatype. If not provided, will be read from the binary source.</param>
        /// <param name="Embedded">If the object is embedded into another.</param>
        /// <returns>Deserialized object.</returns>
        public override object Deserialize(IDeserializer Reader, uint?DataType, bool Embedded)
        {
            if (!DataType.HasValue)
            {
                DataType = Reader.ReadBits(6);
            }

            switch (DataType.Value)
            {
            case ObjectSerializer.TYPE_BOOLEAN: return(Enum.ToObject(this.enumType, Reader.ReadBoolean() ? 1 : 0));

            case ObjectSerializer.TYPE_BYTE: return(Enum.ToObject(this.enumType, Reader.ReadByte()));

            case ObjectSerializer.TYPE_INT16: return(Enum.ToObject(this.enumType, Reader.ReadInt16()));

            case ObjectSerializer.TYPE_INT32: return(Enum.ToObject(this.enumType, Reader.ReadInt32()));

            case ObjectSerializer.TYPE_INT64: return(Enum.ToObject(this.enumType, Reader.ReadInt64()));

            case ObjectSerializer.TYPE_SBYTE: return(Enum.ToObject(this.enumType, Reader.ReadSByte()));

            case ObjectSerializer.TYPE_UINT16: return(Enum.ToObject(this.enumType, Reader.ReadUInt16()));

            case ObjectSerializer.TYPE_UINT32: return(Enum.ToObject(this.enumType, Reader.ReadUInt32()));

            case ObjectSerializer.TYPE_UINT64: return(Enum.ToObject(this.enumType, Reader.ReadUInt64()));

            case ObjectSerializer.TYPE_DECIMAL: return(Enum.ToObject(this.enumType, Reader.ReadDecimal()));

            case ObjectSerializer.TYPE_DOUBLE: return(Enum.ToObject(this.enumType, Reader.ReadDouble()));

            case ObjectSerializer.TYPE_SINGLE: return(Enum.ToObject(this.enumType, Reader.ReadSingle()));

            case ObjectSerializer.TYPE_STRING:
            case ObjectSerializer.TYPE_CI_STRING: return(Enum.Parse(this.enumType, Reader.ReadString()));

            case ObjectSerializer.TYPE_ENUM: return(Reader.ReadEnum(this.enumType));

            case ObjectSerializer.TYPE_NULL: return(null);

            default: throw new Exception("Expected an enum value.");
            }
        }