46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
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 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 partial class Serializer
|
|
{
|
|
public static byte[] Serialize(SSDSerializable serializableObject)
|
|
{
|
|
return serializableObject.GetBytes();
|
|
}
|
|
|
|
public static T Deserialize<T>(byte[] stream)where T : SSDSerializable
|
|
{
|
|
T serializableObject = (T)Activator.CreateInstance<T>();
|
|
serializableObject.BuildFromByteStream(stream);
|
|
return serializableObject;
|
|
}
|
|
}
|
|
} |