/// <summary> /// Deserializes an object from a binary source. /// </summary> /// <param name="Reader">Binary 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(BinaryDeserializer 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."); } }
/// <summary> /// Deserializes an object from a binary source. /// </summary> /// <param name="Reader">Binary 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(BinaryDeserializer Reader, uint?DataType, bool Embedded) { if (!DataType.HasValue) { DataType = Reader.ReadBits(6); } switch (DataType.Value) { case ObjectSerializer.TYPE_BOOLEAN: return(Reader.ReadBoolean()); case ObjectSerializer.TYPE_BYTE: return(Reader.ReadByte() != 0); case ObjectSerializer.TYPE_INT16: return(Reader.ReadInt16() != 0); case ObjectSerializer.TYPE_INT32: return(Reader.ReadInt32() != 0); case ObjectSerializer.TYPE_INT64: return(Reader.ReadInt64() != 0); case ObjectSerializer.TYPE_SBYTE: return(Reader.ReadSByte() != 0); case ObjectSerializer.TYPE_UINT16: return(Reader.ReadUInt16() != 0); case ObjectSerializer.TYPE_UINT32: return(Reader.ReadUInt32() != 0); case ObjectSerializer.TYPE_UINT64: return(Reader.ReadUInt64() != 0); case ObjectSerializer.TYPE_DECIMAL: return(Reader.ReadDecimal() != 0); case ObjectSerializer.TYPE_DOUBLE: return(Reader.ReadDouble() != 0); case ObjectSerializer.TYPE_SINGLE: return(Reader.ReadSingle() != 0); case ObjectSerializer.TYPE_MIN: return(false); case ObjectSerializer.TYPE_MAX: return(true); case ObjectSerializer.TYPE_NULL: return(null); default: throw new Exception("Expected a boolean value."); } }