Action Message Format
Encyclopedia
Action Message Format is a binary format used to serialize objects graphs such ActionScript
ActionScript
ActionScript is an object-oriented language originally developed by Macromedia Inc. . It is a dialect of ECMAScript , and is used primarily for the development of websites and software targeting the Adobe Flash Player platform, used on Web pages in the form of...

 objects and XML, or send messages between an Adobe Flash
Adobe Flash
Adobe Flash is a multimedia platform used to add animation, video, and interactivity to web pages. Flash is frequently used for advertisements, games and flash animations for broadcast...

 client and a remote service, usually a Flash Media Server
Adobe Flash Media Server
Flash Media Server is a proprietary data and media server from Adobe Systems . This server works with the Flash Player runtime to create media driven, multiuser RIAs . The server uses ActionScript 1, an ECMAScript based scripting language, for server-side logic...

 or third party alternatives.

The format is often used in conjunction with Adobe's RTMP
Real Time Messaging Protocol
Real Time Messaging Protocol was initially a proprietary protocol developed by Macromedia for streaming audio, video and data over the Internet, between a Flash player and a server...

 to establish connections and control commands for the delivery of streaming media. In this case, the AMF data is encapsulated in a chunk which has a header which defines things as the message length and type (whether it is a "ping", "command" or media data).

Protocol

AMF was introduced with Flash Player
Adobe Flash Player
The Adobe Flash Player is software for viewing multimedia, Rich Internet Applications and streaming video and audio, on a computer web browser or on supported mobile devices. Flash Player runs SWF files that can be created by the Adobe Flash authoring tool, by Adobe Flex or by a number of other...

 6, and this version is referred to as AMF0. It was unchanged until the release of Flash Player 9 and ActionScript
ActionScript
ActionScript is an object-oriented language originally developed by Macromedia Inc. . It is a dialect of ECMAScript , and is used primarily for the development of websites and software targeting the Adobe Flash Player platform, used on Web pages in the form of...

 3.0, when new data types and language features prompted an update, called AMF3.

Adobe Systems
Adobe Systems
Adobe Systems Incorporated is an American computer software company founded in 1982 and headquartered in San Jose, California, United States...

 published the AMF binary data protocol specification on December 13, 2007 and announced that it will support the developer community to make this protocol available for every major server platform.

AMF0

The protocol specifies a number of data types that can be encoded and Adobe states that the format is rather meant at encoding object graphs. These can be nested objects which can include basic data types such as strings, numbers and booleans. XML is supported as a native type. Each type is denoted by a single byte using the example codes below (for AMF0):

  • Number - 0x00 (Encoded as IEEE 64-bit double precision floating point number)

  • Boolean - 0x01 (Encoded as a single byte of value 0x00 or 0x01)

  • String - 0x02 (ASCII
    ASCII
    The American Standard Code for Information Interchange is a character-encoding scheme based on the ordering of the English alphabet. ASCII codes represent text in computers, communications equipment, and other devices that use text...

     encoded)

  • Object - 0x03 (Set of key/value pairs)

  • Null - 0x05

  • Array - 0x08

  • Object/Array End - 0x09



Although, strictly speaking, AMF is only a data encoding format, it is usually found encapsulated in a RTMP Message, which has a header appended in front of any AMF data that follows. This header is split into the Basic Header and Chunk Message Header. The Basic Header which is always present, is usually a single composite byte which, depending on its value, can be extended to 2 extra bytes. The Chunk Message Header contains meta-data information such as the message size in bytes, the timestamp and message type. AMF Objects are sets of key value pairs, where keys are encoded as strings but without a type-definition byte in front (0x02). All other data is preceded by a type definition byte and in the case of strings, 2 bytes denoting length. Null types have no bytes while numbers are encoded as double precision floating point. An example is shown below as captured when a flash client executes the following code:


var stream:NetStream = new NetStream(connectionObject);


this will generate the following Chunk:
Hex Code ASCII
03 00 0b 68 00 00 19 14 00 00 00 00 02 00 0C 63 72 65 61 74 65 53 74 72 65 61 6D 00 40 00 00 00 00 00 00 00 05 . . @ I . . . . . . . . . . . . c r e a t e S t r e a m . @ . . . . . . . .


The packet starts with a Basic Header of a single byte (0x03). It represents a compact value, where the 2 most significant bits (b00000011) define the Chunk Header Type and the rest form the Chunk Stream ID (which servers to multiplex more than one message in a TCP packet). The possibles Chunk Stream ID values are 3 - 65599 with a value of 1 signifying an extended ID format, in which case there will be 2 bytes following that. The possible values of the Chunk Header Type (2 most significant bits) are:
  • 00 signifies a 12 byte header (full header).
  • 01 = 8 bytes (like type 0 but with the 4 timestamp bytes omitted and derived from the previous packet)
  • 10 = 4 bytes (1rst byte + 3 new timestamp bytes)
  • 11 = 1 byte (only the 1rst byte is included, the rest are derived from the previous packet)


The next bytes are decoded as follows:
  • byte #1 (1 byte) = Chunk Header Type.
  • byte #2-4 (3 bytes) = Timestamp delta.
  • byte #5-7 (3 bytes) = Packet Length - in this case it is 0x00001A = 26 bytes.
  • byte #8 (1 byte) = Message Type ID - here 0x14 defines an AMF0 encoded command message.
  • byte #9-12 (4 bytes) = Message Stream ID. This (strangely) is in little-endian order


The Message Type ID byte defines the whether the packet contains audio/video data, a remote object or a command. Some possible values are for are:
  • 0x01 = Set Packet Size Message.
  • 0x04 = Ping Message.
  • 0x05 = Server Bandwidth
  • 0x06 = Client Bandwidth.
  • 0x08 = Audio Packet.
  • 0x09 = Video Packet.
  • 0x11 = An AMF3 type command.
  • 0x12 = Invoke (onMetaData info is sent as such).
  • 0x14 = An AMF0 type command.


Some of the message types shown above, such as Ping and Set Client/Server Bandwidth, are considered low level RTMP protocol messages which do not use the AMF encoding format. Command messages on the other hand, whether AMF0 or AMF3, use the format and have the general form shown below:


"command"


The transaction id is used for commands that can have a reply. The value can be either a string like in the example above or an object composed of key/value pairs.

Following the header, 0x02 denotes a string of size 0x000C and values 0x63 0x72 ... 0x6D ("createStream" command). Following that we have a 0x00 (number) which is the transaction id of value 2.0. The last byte is 0x05 (null) which means there are no arguments.

A more complex example can be seen here as the "_result" message returned in response to the "connect" command sent from the flash client:
Hex Code ASCII
03 00 00 00 00 01 05 14 00 00 00 00 02 00 07 5F 72 65 73 75 6C 74 00 3F F0 00 00 00 00 00 00 03 00 06 66 6D 73 56 65 72 02 00 0E 46 4D 53 2F 33 2C 35 2C 35 2C 32 30 30 34 00 0C 63 61 70 61 62 69 6C 69 74 69 65 73 00 40 3F 00 00 00 00 00 00 00 04 6D 6F 64 65 00 3F F0 00 00 00 00 00 00 00 00 09 03 00 05 6C 65 76 65 6C 02 00 06 73 74 61 74 75 73 00 04 63 6F 64 65 02 00 1D 4E 65 74 43 6F 6E 6E 65 63 74 69 6F 6E 2E 43 6F 6E 6E 65 63 74 2E 53 75 63 63 65 73 73 00 0B 64 65 73 63 72 69 70 74 69 6F 6E 02 00 15 43 6F 6E 6E 65 63 74 69 6F 6E 20 73 75 63 63 65 65 64 65 64 2E 00 04 64 61 74 61 08 00 00 00 00 00 07 76 65 72 73 69 6F 6E 02 00 0A 33 2C 35 2C 35 2C 32 30 30 34 00 00 09 00 08 63 6C 69 65 6E 74 69 64 00 41 D7 9B 78 7C C0 00 00 00 0E 6F 62 6A 65 63 74 45 6E 63 6F 64 69 6E 67 00 40 08 00 00 00 00 00 00 00 00 09 . . . . . . . . . . . . . . . _ r e s u l t . ? . . . . . . . . . f m s V e r . . . F M S / 3 , 5 , 5 , 2 0 0 4 . . c a p a b i l i t i e s . @ ? . . . . . . . . m o d e . . . . . . . . . . . . . . l e v e l . . .s t a t u s . . . c o d e . . . N e t C o n n e c t i o n . C o n n e c t . S u c c e s s . . d e s c r i p t i o n . . . C o n n e c t i o n su c c e e d e d . . d a t a . . . . . . . version . . . 3 , 5 , 5 , 2 0 0 4 . . . . . . c l i e n t i d . . . . . . . . . . . o b j e c t E n c o d i n g . @ . . . . . . . . . .


legend: object start and object end object keys object values array

The AMF message starts with a header type 0 and the rest of body is decoded as follows:

(command) “_result”
(transaction id) 1
(value)
[1] { fmsVer: "FMS/3,5,5,2004"
capabilities: 31.0
mode: 1.0 },
[2] { level: “status”,
code: “NetConnection.Connect.Succeeded",
description: “Connection succeeded”,
data: (array) {
version: “3,5,5,2004” },
clientId: 1584259571.0,
objectEncoding: 3.0 }


Here we can see an array (in turquoise) as a value of the 'data' key which has one member. We can see the objectEncoding value to be 3. This means that subsequent messages are going to be sen with the 0x11 message type which will imply an AMF3 encoding.

AMF3

The newer version of the protocol specifies some changes in the data types above. A message containing AMF3 encoded data has the message type byte set to 0x11 instead of 0x14 and will contain an extra 0x00 byte at the end of the header. AMF3 is in fact encapsulated within AMF0 and it is possible that a message of type AMF3 to contain no such data. The data type markers are as follows:
  • Undefined - 0x00
  • Null - 0x01
  • False - 0x02
  • True - 0x03
  • Integer - 0x04
  • Double - 0x05
  • String - 0x06
  • XML - 0x07
  • Date - 0x08
  • Array - 0x09
  • Object - 0x0A
  • XML End - 0x0B

Support for AMF

The various AMF Protocols are supported by many server-side languages and technologies, in the form of libraries and services that must be installed and integrated by the application developer.

Platforms:
  • ColdFusion
    ColdFusion
    In computing, ColdFusion is the name of a commercial rapid application development platform invented by Jeremy and JJ Allaire in 1995. ColdFusion was originally designed to make it easier to connect simple HTML pages to a database, by version 2 it had...

     -
  • haXe
    HaXe
    haXe is a versatile open-source high-level multiplatform programming language described on its website as a "universal language".It can produce:* Flash applications and games* Multi-platform client-side web applications* Apache CGI web applications...

     - haXe Remoting hxformat
  • Java
    Java (programming language)
    Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

     - Adobe BlazeDS, Adobe LiveCycle Data Services (formerly known as Flex Data Services), Exadel Flamingo, RED 5, Cinnamon, OpenAMF, Pimento, Granite, WebORB for Java
  • .NET
    .NET Framework
    The .NET Framework is a software framework that runs primarily on Microsoft Windows. It includes a large library and supports several programming languages which allows language interoperability...

     - WebORB for .NET, FluorineFx (LGPL), AMF.NET (development stopped)
  • PHP
    PHP
    PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...

     - AMFPHP, SabreAMF, WebORB for PHP, Zend_Amf, php-amf3 extension
  • Python
    Python (programming language)
    Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

     - PyAMF, Flashticle, amfast, Plasma
  • Perl
    Perl
    Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

     - AMF::Perl, Storable::AMF, AMF::Connection
  • Curl - Curl Data Services
  • Ruby
    Ruby (programming language)
    Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...

     - RubyAMF, WebORB for Rails, Rocket AMF
  • Erlang - Erlang-AMF
  • JavaScript
    JavaScript
    JavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles....

     - JSAMF
  • ABAP
    ABAP
    ABAP , is a high-level programming language created by the German software company SAP...

     - ABAP AMF (early stage)
  • Delphi
    Delphi
    Delphi is both an archaeological site and a modern town in Greece on the south-western spur of Mount Parnassus in the valley of Phocis.In Greek mythology, Delphi was the site of the Delphic oracle, the most important oracle in the classical Greek world, and a major site for the worship of the god...

     - kbmMW (extensive AMF0/AMF3 support)
  • iOS
    IOS
    iOS is an operating system for iPad, iPhone, iPod Touch, and Apple TV.IOS may also refer to:-Companies and organisations:* Illinois Ornithological Society, American state-based bird club...

     - CocoaAMF


Frameworks:
  • Ruby on Rails
    Ruby on Rails
    Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.-History:...

     - RubyAMF
  • Zend Framework
    Zend Framework
    Zend Framework is an open source, object-oriented web application framework implemented in PHP 5 and licensed under the New BSD License.-Licensing:...

     - Zend_AMF
  • OSGi Framework
    OSGi
    The Open Services Gateway initiative framework is a module system and service platform for the Java programming language that implements a complete and dynamic component model, something that does not exist in standalone Java/VM environments...

     - AMF3 for OSGi
  • Django - Django AMF
  • CakePHP
    CakePHP
    CakePHP is an open source web application framework for producing web applications. It is written in PHP, modeled after the concepts of Ruby on Rails, and distributed under the MIT License.-History:...

     - CakeAMFPHP
  • Grails (framework)
    Grails (Framework)
    Grails is an open source web application framework which uses the Groovy programming language . It is intended to be a high-productivity framework by following the "coding by convention" paradigm, providing a stand-alone development environment and hiding much of the configuration detail from the...

     - BlazeDS
  • Trac
    Trac
    Trac is an open source, web-based project management and bug-tracking tool. The program is inspired by CVSTrac, and was originally named svntrac due to its ability to interface with Subversion. It is developed and maintained by Edgewall Software....

     - TracRpcProtocolsPlugin. Version 1.1.0 (or higher) of XmlRpcPlugin is required.
  • Web2py
    Web2py
    Web2py is an open source web application framework. Web2py is written in the Python language and is programmable in Python. Since web2py was originally designed as a teaching tool with emphasis on ease of use and deployment, it does not have any project-level configuration files. Web2py was...

     - PyAMF
  • kbmMW - (extensive AMF0/AMF3 support for Delphi)
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK