/// <summary> /// Deserialize the specified type into the provided instance /// </summary> /// <param name="instance">The instance to populate</param> /// <param name="type">Type to deserialize</param> /// <param name="allData">Data to read</param> /// <param name="instanceStart">The current instance's offset from the beginning of the data</param> /// <param name="staticOffset">A static offset that is applied when following pointers</param> /// <param name="stringProvider">An interned string provider to retrieve string values from</param> /// <returns>The hydrated instance</returns> public static object DeserializeInto(object instance, Type type, Stream allData, int instanceStart = 0, int staticOffset = 0, IInternedStringProvider stringProvider = null) { if (deserializers.TryGetValue(type, out var desers) && desers.deserializeIntoReference != null) { return(desers.deserializeIntoStreamReference(instance, allData, instanceStart, staticOffset, stringProvider)); } throw new NotSupportedException($"Type '{type.Name}' was not found in the deserializer collection"); }
/// <summary> /// Deserialize the specified type into the provided instance /// </summary> /// <typeparam name="T">Type to deserialize</param> /// <param name="instance">The instance to populate</param> /// <param name="allData">Data to read</param> /// <param name="instanceStart">The current instance's offset from the beginning of the data</param> /// <param name="staticOffset">A static offset that is applied when following pointers</param> /// <param name="stringProvider">An interned string provider to retrieve string values from</param> /// <returns>The hydrated instance</returns> public static T DeserializeInto <T>(T instance, Stream allData, int instanceStart = 0, int staticOffset = 0, IInternedStringProvider stringProvider = null) { if (deserializers.TryGetValue(typeof(T), out var deser)) { return(((StreamDeserializeInto <T>)deser.deserializeIntoStreamGeneric)(instance, allData, instanceStart, staticOffset, stringProvider)); } throw new NotSupportedException($"Type '{typeof(T).Name}' was not found in the deserializer collection"); }
/// <summary> /// Instance method to provide args to always use, just dispatches to static with those args /// </summary> public BlamSerializer(Memory <byte> data, IInternedStringProvider stringProvider = null) { this.data = data; this.stringProvider = stringProvider; }