AMF is serialized as an object and AMF is serialized as a binary byte stream.

Source: Internet
Author: User

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;

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.