Getting started with AMF

Source: Internet
Author: User

To explain how to use the package FluorineFx. AMF3 for AMF data, follow these steps.

FluorineFx. AMF3.ByteArray br = new FluorineFx. AMF3.ByteArray (new MemoryStream (bb); br. position = 0; br. readShort (); // amf version br. readShort (); // Number of headers br. readShort (); // number of bodies br. readUTFBytes (uint) (br. readShort (); // target length and string br. readUTFBytes (uint) (br. readShort (); // Response length and string br. readInt (); // body length br. readByte (); // body type object o = br. readObject ();

 

Use C # To simulate client requests and AMF request packets.

Class AMF_Post_Data {public List <byte> message; /// <summary> /// initialize Message /// </summary> /// <param name = "at"> </param> /// <param name = "headers"> </param> // <param name = "bodies"> </param> public AMF_Post_Data (AMFType, int headers, int bodies) {// AMF version if (at = AMFType. AMF0) {message = new List <byte> (new byte [] {0x00, 0x00});} else if (at = AMFType. AMF3) {message = new List <byte> (new byte [] {0x00, 0x03});} // Number of headers: message. add (BitConverter. getBytes (headers) [1]); message. add (BitConverter. getBytes (headers) [0]); // number of body messages. add (BitConverter. getBytes (bodies) [1]); message. add (BitConverter. getBytes (bodies) [0]);} /// <summary> /// add Target /// </summary> /// <param name = "target"> </param> /// <param name = "Response"> </param> public void AddTargetAndResponse (string target, string Response) {// Add the Target length message. add (BitConverter. getBytes (target. length) [1]); message. add (BitConverter. getBytes (target. length) [0]); // Add the Target content message. addRange (Encoding. default. getBytes (target); // Add the Response length message. add (BitConverter. getBytes (Response. length) [1]); message. add (BitConverter. getBytes (Response. length) [0]); // Add the Response content message. addRange (Encoding. default. getBytes (Response ));} /// <summary> /// add Body /// </summary> /// <param name = "length"> </param> /// <param name = "Content"> </param> public void AddBody (AMF_Post_Data_Body apdb) {message. addRange (apdb. getLength (); message. addRange (apdb. content. toArray () ;}} class AMF_Post_Data_Body {private byte [] length = new byte [4]; public List <byte> Content = new List <byte> (); /// <summary> /// initialize the Body /// </summary> /// <param name = "dt"> </param> /// <param name = "ArrayLength"> </param> public AMF_Post_Data_Body (DataType dt, int ArrayLength) {// Add the type identifier Content. add (byte) dt); // Add the length if (dt = DataType. array) {Content. add (BitConverter. getBytes (ArrayLength) [3]); Content. add (BitConverter. getBytes (ArrayLength) [2]); Content. add (BitConverter. getBytes (ArrayLength) [1]); Content. add (BitConverter. getBytes (ArrayLength) [0]);} public void AddData (DataType dt, string value) {// Add a type identifier Content. add (byte) dt); switch (dt) {case DataType. number: AddData_Number (double. parse (value); break; case DataType. string: AddData_String (value); break; case DataType. boolean: AddData_Boolean (Boolean. parse (value); break ;}} # region more types of Processing Methods // <summary> // Boolean // </summary> // <param name = "p"> </param> private void AddData_Boolean (bool p) {if (p) Content. add (0x01); else Content. add (0x00 );} /// <summary> /// String /// </summary> /// <param name = "value"> </param> private void AddData_String (string value) {// Add Content. add (BitConverter. getBytes (value. length) [1]); Content. add (BitConverter. getBytes (value. length) [0]); // Add Content. addRange (Encoding. default. getBytes (value ));} /// <summary> // Number // </summary> /// <param name = "p"> </param> private void AddData_Number (double p) {byte [] B = new byte [8]; B = BitConverter. getBytes (p); for (int I = 7; I>-1; I --) {Content. add (B) ;}# endregion public byte [] getLength () {length [0] = BitConverter. getBytes (Content. count) [3]; length [1] = BitConverter. getBytes (Content. count) [2]; length [2] = BitConverter. getBytes (Content. count) [1]; length [3] = BitConverter. getBytes (Content. count) [0]; return length ;}# region type enumeration public enum AMFType {AMF0, AMF3} public enum DataType {Number = 0, Boolean = 1, String = 2, untypedObject = 3, MovieClip = 4, Null = 5, Undefined = 6, ReferencedObject = 7, MixedArray = 8, End = 9, Array = 10, // 0x0A Date = 11, // 0x0B LongString = 12, // 0x0C TypeAsObject = 13, // 0x0D Recordset = 14, // 0x0E Xml = 15, // 0x0F TypedObject = 16, // 0x10 AMF3data = 17 // 0x11} # endregion

 

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.