amfio 1.0 — AMF0/AMF3 and SharedObject library for OpenFL
Today, I'm happy to introduce version 1.0 of the new amfio open source project, which allows reading and writing AMF data using the
ByteArray class from OpenFL.
This is the first of many projects that I'll be releasing as part of the Feathers UI v1.0 release week celebration.
The AMF I/O library aims to be the best and most complete implementation of the AMF (Action Message Format) specification for OpenFL. For those who might not be aware, AMF0 and AMF3 are binary formats that were originally developed for Adobe Flash Player to transfer data between client and server. AMF can serialize objects in a more compact way than common plain text data formats, like JSON or XML, which means that sending AMF data over a network requires less bandwidth.
Additionally, the library includes the ability to read and write Flash Local Shared Object (.sol) files, commonly known as "Flash cookies". This file format stores serialized objects using AMF serialization. The same
SharedObject API from Flash Player is also available in Adobe AIR, which is used to create desktop and mobile apps. Developers building apps with AIR commonly used Local Shared Objects to store application settings and other important data. The included
SolWriter classes should be considered especially useful for migrating Adobe AIR app Local Shared Object data to Haxe and OpenFL.
Other ways of using AMF
Backend services that understand AMF can be used to transfer strongly typed objects that exist both server-side and client-side. A
RemoteObject service on the frontend is used to call backend methods with typed parameters and to receive typed results back.
See feathersui-rpc-services for a
RemoteObjectservice implementation based on amfio for OpenFL and Feathers UI
Common backend libraries for passing remote objects include BlazeDS, and AMFPHP, and there are similar implementations available for many other languages too.
AMF is also used as part of RTMP (Real Time Messaging Protocol) for communicating with streaming media servers. RTMP not only uses AMF to reduce required bandwidth, it also keeps a persistent connection open to reduce latency.
Common backends supporting RTMP communication include the proprietary Adobe Flash Media Server and the open source Red5 server.
What about the Haxe "format" library?
The Haxe format library includes support for a number of common data formats, including AMF. It's a really useful library for Haxe developers. In fact, the
ByteArray.writeObject() APIs in OpenFL currently use the format library internally, when AMF0/AMF3
objectEncoding is specified. However, the implementation of AMF0/AMF3 in the format library is missing certain AMF features that prevent it from supporting all AMF use-cases.
In particular, it cannot handle serializing class instances — forcing the use of simpler anonymous structures instead of stricter/stronger typing. It also cannot handle references to duplicate strings or objects (a key feature for reducing data transfer size). In certain cases, data that should be ideally deserialized as an
Array might instead become an anonymous structure with integer index values stored as string keys instead (which makes porting existing code to Haxe a bit more tedious).
Install amfio v1.0.0
amfio v1.0.0 may be installed using the haxelib install command in your terminal.
haxelib install amfio 1.0.0
The v1.0.0 API Reference includes descriptions of all APIs available in amfio.
Questions or comments?
If you need some help, or want to give feedback, feel free to create a thread in either the Feathers UI Community forum or the OpenFL Community forum.