using System; using JetBrains.Annotations; using Robust.Shared.Serialization.Manager.Result; using Robust.Shared.Serialization.Markdown; using Robust.Shared.Serialization.Markdown.Validation; using Robust.Shared.Serialization.TypeSerializers.Interfaces; namespace Robust.Shared.Serialization.Manager { public interface ISerializationManager { /// /// Initializes the serialization manager. /// void Initialize(); /// /// Shuts down the serialization manager. /// void Shutdown(); /// /// Checks if a type has a data definition defined for it. /// /// The type to check for. /// True if it does, false otherwise. bool HasDataDefinition(Type type); #region Validation /// /// Validates that a node has all the properties required by a certain type with its serializer. /// /// The type to check for. /// The node to check. /// The context to use, if any. /// /// A node with whether or not is valid and which of its fields /// are invalid, if any. /// ValidationNode ValidateNode(Type type, DataNode node, ISerializationContext? context = null); /// /// Validates that a node has all the properties required by a certain type with its serializer. /// /// The node to check. /// The context to use, if any. /// /// A node with whether or not is valid and which of its fields /// are invalid, if any. /// ValidationNode ValidateNode(DataNode node, ISerializationContext? context = null); ValidationNode ValidateNodeWith(Type type, Type typeSerializer, DataNode node, ISerializationContext? context = null); ValidationNode ValidateNodeWith(TNode node, ISerializationContext? context = null) where TSerializer : ITypeValidator where TNode : DataNode; #endregion /// /// Creates a deserialization result from a generic type and its fields, /// populating the object. /// /// The fields to use for deserialization. /// Whether or not to skip running /// The type to populate. /// A result with the populated type. DeserializationResult CreateDataDefinition(DeserializedFieldEntry[] fields, bool skipHook = false) where T : notnull, new(); #region Populate /// /// Creates a deserialization result from a generic type and its definition, /// populating the object. /// /// The object to populate. /// The data to use for deserialization. /// Whether or not to skip running /// The type of to populate. /// A result with the populated object. DeserializationResult PopulateDataDefinition(T obj, DeserializedDefinition definition, bool skipHook = false) where T : notnull, new(); /// /// Creates a deserialization result from an object and its definition, /// populating the object. /// /// The object to populate. /// The data to use for deserialization. /// Whether or not to skip running /// A result with the populated object. DeserializationResult PopulateDataDefinition(object obj, IDeserializedDefinition definition, bool skipHook = false); #endregion #region Read /// /// Deserializes a node into an object, populating it. /// /// The type of object to populate. /// The node to deserialize. /// The context to use, if any. /// Whether or not to skip running /// A result with the deserialized object. DeserializationResult Read(Type type, DataNode node, ISerializationContext? context = null, bool skipHook = false); /// /// Deserializes a node into an object, populating it. /// /// The type of object to deserialize into. /// The node to deserialize. /// The context to use, if any. /// Whether or not to skip running /// The deserialized object or null. public object? ReadValue(Type type, DataNode node, ISerializationContext? context = null, bool skipHook = false); /// /// Deserializes a node into an object of the given , /// directly casting it to the given generic type . /// /// The type of object to deserialize into. /// The node to deserialize. /// The context to use, if any. /// Whether or not to skip running /// The generic type to cast the resulting object to. /// The deserialized casted object, or null. T? ReadValueCast(Type type, DataNode node, ISerializationContext? context = null, bool skipHook = false); /// /// Deserializes a node into a populated object of the given generic type /// /// The node to deserialize. /// The context to use, if any. /// Whether or not to skip running /// The type of object to create and populate. /// The deserialized object, or null. T? ReadValue(DataNode node, ISerializationContext? context = null, bool skipHook = false); DeserializationResult ReadWithTypeSerializer(Type value, Type serializer, DataNode node, ISerializationContext? context = null, bool skipHook = false); #endregion #region Write /// /// Serializes a value into a node. /// /// The value to serialize. /// /// Whether or not to always write the given values into the resulting node, /// even if they are the default. /// /// The context to use, if any. /// The type to serialize. /// A serialized datanode created from the given . DataNode WriteValue(T value, bool alwaysWrite = false, ISerializationContext? context = null); /// /// Serializes a value into a node. /// /// The type of the to serialize as. /// The value to serialize. /// /// Whether or not to always write the given values into the resulting node, /// even if they are the default. /// /// The context to use, if any. /// /// A serialized datanode created from the given /// of type . /// DataNode WriteValue(Type type, object? value, bool alwaysWrite = false, ISerializationContext? context = null); DataNode WriteWithTypeSerializer(Type type, Type serializer, object? value, bool alwaysWrite = false, ISerializationContext? context = null); #endregion #region Copy /// /// Copies the values of one object into another. /// This does not guarantee that the object passed as /// is actually mutated. /// /// The object to copy values from. /// The object to copy values into. /// The context to use, if any. /// Whether or not to skip running /// /// The object with the copied values. /// This object is not necessarily the same instance as the one passed /// as . /// [MustUseReturnValue] object? Copy(object? source, object? target, ISerializationContext? context = null, bool skipHook = false); /// /// Copies the values of one object into another. /// This does not guarantee that the object passed as /// is actually mutated. /// /// The object to copy values from. /// The object to copy values into. /// The context to use, if any. /// Whether or not to skip running /// The type of the objects to copy from and into. /// /// The object with the copied values. /// This object is not necessarily the same instance as the one passed /// as . /// [MustUseReturnValue] T? Copy(T? source, T? target, ISerializationContext? context = null, bool skipHook = false); [MustUseReturnValue] object? CopyWithTypeSerializer(Type typeSerializer, object? source, object? target, ISerializationContext? context = null, bool skipHook = false); #endregion #region CreateCopy /// /// Creates a copy of the given object. /// /// The object to copy. /// The context to use, if any. /// Whether or not to skip running /// A copy of the given object. object? CreateCopy(object? source, ISerializationContext? context = null, bool skipHook = false); /// /// Creates a copy of the given object. /// /// The object to copy. /// The context to use, if any. /// Whether or not to skip running /// The type of the object to copy. /// A copy of the given object. T? CreateCopy(T? source, ISerializationContext? context = null, bool skipHook = false); #endregion #region Flags And Constants Type GetFlagTypeFromTag(Type tagType); int GetFlagHighestBit(Type tagType); Type GetConstantTypeFromTag(Type tagType); #endregion } }