When Flex is used as the front-end page drive socket communication, the AMF format is generally used for sending and receiving. Therefore, the conversion of different data formats is required.
The following describes how to serialize AMF to an object and AMF to a binary byte stream,CodeAs follows:
// Convert AMF Format byte streams into objects
Public static t amf_deserializer <t> (byte [] buffer, int length)
{
Memorystream stream = new memorystream (buffer, 0, length );
Bytearray = new bytearray (Stream );
Object OBJ = bytearray. readobject ();
If (OBJ = NULL)
{
Return default (t );
}
Return (t) OBJ;
}
// Converts an object to a byte stream in AMF format
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;
}