internal T Deserialize <T> (byte[] _serializationData, T _targetObject) { try { // Check serialization data if (_serializationData == null) { throw new Exception("[RS] Serialization data is null."); } // Load serialization data to stream buffer BinaryStreamReader.LoadBuffer(_serializationData); // Get version info int _serializationFormatVersion = GetVersionInfo(); // Check if serialization version is compatible if (_serializationFormatVersion > Constants.kSerializationSupportedFormatVersions) { throw new Exception("[RS] Failed to deserialize object. Serialized data format not supported please update RS plugin to the most recent version."); } ObjectReader _objectReader = GetObjectReader(_serializationFormatVersion); // Start deserializing data Type _deserializedType; object _deserializedObj = _objectReader.ReadObjectValue(BinaryStreamReader, out _deserializedType, _targetObject); if (_deserializedObj == null) { return(default(T)); } else if (typeof(T).IsInstanceOfType(_deserializedObj)) { return((T)_deserializedObj); } else { throw new Exception(string.Format("[RS] Deserialized object isnt an object of type={0}.", typeof(T))); } } finally { Reset(); } }
internal int GetVersion(byte[] _serializationData) { try { // Check serialization data if (_serializationData == null) { throw new Exception("[RS] Serialization data is null."); } // Load serialization data to stream buffer BinaryStreamReader.LoadBuffer(_serializationData); // Get version info return(GetVersionInfo()); } finally { Reset(); } }