Actionscript data types in AMF

AMF represents ActionScript objects by a single byte representing type, and then by a type-specific byte array that may be of fixed length, may contain length information, or may come with its own end code. The Flash player encodes Actionscript objects according to the following table. The following types have been discovered so far:

Type Byte code Notes
Number 0x00
Boolean 0x01
String 0x02
Object 0x03
MovieClip 0x04 Not available in Remoting
Null 0x05
Undefined 0x06
Reference 0x07
MixedArray 0x08
EndOfObject 0x09 See Object
Array 0x0a
Date 0x0b
LongString 0x0c
Unsupported 0x0d
Recordset 0x0e Remoting, server-to-client only
XML 0x0f
TypedObject (Class instance) 0x10
AMF3 data 0x11 Sent by Flash player 9+

0x00: Number

Represented as 9 bytes: 1 byte for 0x00 and 8 bytes a double representing the value of the number.

0x01: Boolean

Represented as 2 bytes: 1 byte for 0x01 and a second, 0x00 for false, 0x01 for true.

0x02: String

Represented as 3 bytes + len(String): 1 byte 0x02, then a UTF8 string, including the top two bytes representing string length as a int.

0x03: Object

Represented as 1 byte, 0x03, then pairs of UTF8 string, the key, and an amf element, ended by three bytes, 0x00 0x00 0x09.

Implemented in PHP as:

$ret = array(); // init the array
$key = $this->inputStream->readUTF(); // grab the key
for ($type = $this->inputStream->readByte(); $type != 9; $type = $this->inputStream->readByte()) {
    $val = $this->readData($type); // grab the value
    $ret[$key] = $val; // save the name/value pair in the array
    $key = $this->inputStream->readUTF(); // get the next name
}
return $ret; // return the array

0x04: MovieClip

MovieClip does not sem to be supported by Remoting. It may be used by other AMF clients such as SharedObjects. FIXME

0x05: Null

1 single byte, 0x05 indicates null

0x06: Undefined

1 single byte, 0x06 indicates null

0x07: Reference

When an ActionScript object refers to itself, such this.self = this, or when objects are repeated within the same scope (for example, as the two parameters of the same function called), a code of 0x07 and an int, the reference number, are written.

The reference counter restarts at 0 in every new scope (scope can mean a specific body or header in the context of Remoting), and increments for every passed object, array, mixedArray and typedObject (class). The first object encountered will have reference number 1, the second 2, and so on. There are two suggestions for when you're not able to deal with references.

  • Return null
  • Return [unresolved reference #x] (this is what happens in AMFPHP)

These are merely suggestions though. A solution for PHP would be to create an array with references to the objects. (using the reference id as a key).

0x08: MixedArray

A MixedArray is indicated by code 0x08, then a Long representing the highest numeric index in the array, or 0 if there are none or they are all negative. After that follow the elements in key : value pairs. Each key is an UTF8 string containing the string length. Numeric keys are represented as strings. A MixedArray is an instance of the ActionScript Array with either of the conditions:

  • The array contains floating point or negative indices
  • The array contains non-numeric keys

MixedArray ends with an empty UTF8 string (0x00 0x00) and 0x09. It is very similar to an 0x03 Object; however the host should convert numeric looking keys to numeric keys, unlike Object.

0x0A: Array

An array is indicated by 0x0A, then a Long for array length, then the array elements themselves. Arrays are always sparse; values for inexistant keys are set to null (0x06) to maintain sparsity. Take the following example:

var a = new Array();
a[0] = "something";
a[10000] = "Something else";

Flash will encode this as 0x0A, then length 10001, then the first element, 9999 times 0x06, then the final element, for a total of over 10 KB. For arrays with very large gaps, the user may want to insert a dummy string key so that the array will be forcefully typed as a MixedArray.

0x0B: Date

Date is represented as 0x0B, then a double, then an int. The double represents the number of milliseconds since 01/01/1970. The int represents the timezone offset in minutes between GMT. Note for the latter than values greater than 720 (12 hours) are represented as 2^16 - the value. Thus GMT+1 is 60 while GMT-5 is 65236.

The Flash player sends a timezone value, however it seems that it does not read it coming back from the server.

0x0C: LongString

LongString is reserved for strings larger then 2^16 characters long. It is represented as 0x0C then a LongUTF.

0x0D: Unsupported

Trying to send values which don't make sense, such as prototypes, functions, built-in objects, etc. will be indicated by a single 0x0D byte.

0x0E: RecordSet

0X0E has been reported as a possible means of transmitting RecordSets. Little information is known about that mechanism however. For the time being, Remoting implementations should stick with the custom class code (0x0A) with the Remoting recordset structure.

0x0F: XML

The XML element is indicated by 0x0F and followed by a LongUTF containing the string representation of the XML object. The receiving gateway may which to wrap this string inside a language-specific standard XML object, or simply pass as a string.

0x10: Typed object

A typed object is indicated by 0x10, then a UTF string indicating class name, and then the same structure as a normal 0x03 Object. The receiving gateway may use a mapping scheme, or send back as a vanilla object or associative array.

0x11: AMF3 data

An AMF message sent from an AS3 client such as the Flash 9 player may break out into AMF3 mode. In this case the next byte will be the AMF3 type code and the data will be in AMF3 format until the decoded object reaches it's logical conclusion (for example, an object has no more keys).

References

Discussion

LLhrnIzhoE, 2013/02/22 13:06
<a href=http://innocultivation.com/#shop>generic tramadol</a> buy tramadol online dogs - buy tramadol online mastercard overnight
moon13, 2013/04/08 03:24
http://www.newmichaelkorspurses.net/ michael kors purses outlet online
http://www.mk-mmichaelkorsoutlet.net/ michael kors outlet online
http://www.guccishoesoutletfactory.net/ gucci shoes outlet online
http://www.northsfaceoutletonline.net/ north face jackets outlet online
http://www.monsterobeats.net/ monster beats outlet online
http://www.coach-storeonline2013.net/ coach store online
http://www.coachoutletinusa.com/ coach outlet online usa
http://www.coachbagsc.com/ coach outlet online coach outlet
http://www.shopcoachfactory.net/ shop.coachfactory.com coachfactory.com/shop
http://www.uswcoay.com/ Coach Outlet Online
http://coachsfactoryoutletonline.webs.com/ Coach outlet online
You could leave a comment if you were logged in.
 
documentation/amf/astypes.txt · Last modified: 2007/11/11 11:38 (external edit)
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki