using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace StgSharp.Data { public abstract class SSDSerializable { public abstract byte SSDTypeCode { get; } public abstract byte[] GetBytes(); public abstract byte[] GetBytes(out int length); internal abstract void BuildFromByteStream(byte[] stream); } public static class SerializableTypeCode { public const byte IndexTable = 1; public const byte Image = 2; public const byte Audio = 3; public const byte Shader = 4; public const byte Text = 5; public const byte RawData = 6; public const byte VirtualFolder = 7; public static string GetNameTail(byte typeCode) { switch (typeCode) { case IndexTable: return "_indexT"; case Image: return "_img"; case Audio: return "_wav"; case Shader: return "_gls"; case Text: return "_txt"; case RawData: return "_raw"; case VirtualFolder: return "_f"; default: throw new ArgumentException("Unknown file type"); } } } public static partial class Serializer { public static byte[] Serialize(SSDSerializable serializableObject) { return serializableObject.GetBytes(); } public static T Deserialize(byte[] stream)where T : SSDSerializable { T serializableObject = (T)Activator.CreateInstance(); serializableObject.BuildFromByteStream(stream); return serializableObject; } } }