When used as a front page Flex driving Socket Communications, AMF format is generally used for transmission and reception, must therefore relates to convert different data formats.
The following provides a method for AMF and AMF sequences into a sequence of objects into a binary byte stream, as follows:
The AMF // byte stream into an object format
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;
}
Reproduced in: https: //www.cnblogs.com/kevinGao/archive/2011/12/17/2776053.html