Data encapsulation and file parsing of AMF protocol (1)

Source: Internet
Author: User

We have explained the AMF protocol. I don't know if you have mastered it, and we also stressed the differences and differences between the two versions. Now we will continue to explain the relevant knowledge. Hope you can get help. Then, we need to encapsulate a complete AMF protocol file. The AMF file is generally divided into four parts: Preface (Preamble) the first two bytes in the preface are used to describe the AMF version. Currently, AMF has two versions: AMF0 and AMF3. if AMF0 is used, the response is 00. 3rd and 4th bytes use a 16-bit integer to indicate the number of AMF headers. Each AMF header consists of the following four parts:

◆ UTF string indicates the Header name

◆ Boolean indicates whether the Header is required

◆ Int32 indicates the Header length, but it seems that this value is FF in many cases, it seems that this field is meaningless 。

◆ The Variable is a certain AMF protocol data type 。

After the Header expression is complete, a 16-bit integer is followed to indicate the number of AMF subjects. After this number, it is the AMF entity 。

AMF consists of the following four parts:

◆ UTF String-Response indicates the request class and method or Response result 。

◆ UTF String-Target is an identifier. It is used to find the corresponding request through the Target to implement the correspondence between the request and the response. Generally, it uses an auto-incrementing integer 。

◆ Int32-indicates the length of the subject. This field is generally useless.

◆ The Variable indicates the data of the subject 。

The body response is an AMF response in the same format as the request body after the client sends an AMF request to the server. However, the content in the body response is different:

◆ Response: the string 'null '.

◆ Target: the Target value of the Request plus "/onStatus", "onResult", or "/onDebugEvents. "/onStatus" is prepared for runtime errors. We generally don't care about this. "/onResult" indicates that the request is called correctly. "/onDebugEvents" is used for debugging, and you do not need to worry about it here. if the Target of the request is '/1', the response of the body after successful call should be'/1/onresult '。

◆ Data: the AMF protocol file object returned after the response 。

After talking about so many estimates, I still feel abstract. The following is an example:


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.