下面提供了AMF序列化為對象和AMF序列化為二進制字節流的方法,代碼如下:
//將AMF格式字節流轉換為對象
public static T AMF_Deserializer<T>(byte[] buffer,int length)
{
MemoryStream stream = new MemoryStream(buffer,0,length);
ByteArray byteArray = new ByteArray(stream);
object obj = byteArray.ReadObject();
if (obj == null)
{
return default(T);
}
return (T)obj;
}
// 將對象轉換為AMF格式的字節流
public static byte[] AMF_Serializer(object obj)
{
FluorineFx.AMF3.ByteArray byteArray = new FluorineFx.AMF3.ByteArray();
byteArray.WriteObject(obj);
byte[] buffer = new byte[byteArray.Length];
byteArray.Position = 0;
byteArray.ReadBytes(buffer, 0, byteArray.Length);
return buffer;
}