/// <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 object Deserialize(BinaryDeserializer Reader, uint?DataType, bool Embedded) { if (!DataType.HasValue) { DataType = Reader.ReadBits(6); } switch (DataType.Value) { case ObjectSerializer.TYPE_ENUM: case ObjectSerializer.TYPE_STRING: case ObjectSerializer.TYPE_CI_STRING: return(Reader.ReadString()); case ObjectSerializer.TYPE_CHAR: return(new string(Reader.ReadChar(), 1)); case ObjectSerializer.TYPE_BOOLEAN: return(Reader.ReadBoolean().ToString()); case ObjectSerializer.TYPE_BYTE: return(Reader.ReadString().ToString()); case ObjectSerializer.TYPE_INT16: return(Reader.ReadInt16().ToString()); case ObjectSerializer.TYPE_INT32: return(Reader.ReadInt32().ToString()); case ObjectSerializer.TYPE_INT64: return(Reader.ReadInt64().ToString()); case ObjectSerializer.TYPE_SBYTE: return(Reader.ReadSByte().ToString()); case ObjectSerializer.TYPE_UINT16: return(Reader.ReadUInt16().ToString()); case ObjectSerializer.TYPE_UINT32: return(Reader.ReadUInt32().ToString()); case ObjectSerializer.TYPE_UINT64: return(Reader.ReadUInt64().ToString()); case ObjectSerializer.TYPE_DECIMAL: return(Reader.ReadDecimal().ToString()); case ObjectSerializer.TYPE_DOUBLE: return(Reader.ReadDouble().ToString()); case ObjectSerializer.TYPE_SINGLE: return(Reader.ReadSingle().ToString()); case ObjectSerializer.TYPE_GUID: return(Reader.ReadGuid().ToString()); case ObjectSerializer.TYPE_DATETIME: return(Reader.ReadDateTime().ToString()); case ObjectSerializer.TYPE_DATETIMEOFFSET: return(Reader.ReadDateTimeOffset().ToString()); case ObjectSerializer.TYPE_TIMESPAN: return(Reader.ReadTimeSpan().ToString()); case ObjectSerializer.TYPE_NULL: return(null); default: throw new Exception("Expected a string 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_GUID: return((Guid?)Reader.ReadGuid()); case ObjectSerializer.TYPE_STRING: return((Guid?)Guid.Parse(Reader.ReadString())); case ObjectSerializer.TYPE_NULL: return(null); default: throw new Exception("Expected a nullable Guid value."); } }
/// <summary> /// Skips the next record key. /// </summary> /// <param name="Reader">Binary deserializer object.</param> /// <returns>If a key was skipped (true), or if no more keys are available (false).</returns> public bool SkipKey(BinaryDeserializer Reader) { if (Reader.BytesLeft < 17) { return(false); } this.recordStart = Reader.Position; Guid Result = Reader.ReadGuid(); if (Result.Equals(Guid.Empty)) { return(false); } else { return(true); } }
/// <summary> /// Gets the next record key. /// </summary> /// <param name="Reader">Binary deserializer object.</param> /// <returns>Next key value, or null if no more keys available.</returns> public object GetKey(BinaryDeserializer Reader) { if (Reader.BytesLeft < 17) { return(null); } this.recordStart = Reader.Position; Guid Result = Reader.ReadGuid(); if (Result.Equals(Guid.Empty)) { return(null); } else { return(Result); } }