AMF has core data types that are there every step of the way for serializing data. These should not be confused with the AMF actionscript data types. The core data types include:
An AMF Byte is the simplest data type to read and write. It is simply an 8-bit byte.
An AMF Int is made up of 2 consecutive bytes. It represents a 16-bit number. The first byte in the file/stream is the most significant bit and the second byte in the file/stream is the LSB.
An AMF MediumInt is made up of 3 consecutive bytes. It represents a 24-bit number. The first byte in the file/stream is the most significant bit and the third byte in the file/stream is the LSB. MediumInt’s appear to be used exclusively by FlashCom.
The AMF Long is made up of 4 consecutive bytes. It represents a 32-bit number. Like the Int and MediumInt, it is unsigned and the LSB is on the right.
The AMF Double is made up of 8 consecutive bytes. It represents a floating point, signed number. The double is little-endian encoded. In PHP a double can be read in the following way (this should also work for any language that has a pack function):
$bytes = substr($this->raw_data, $this->current_byte, 8); $this->current_byte += 8; if ($this->isBigEndian) { $bytes = strrev($bytes); } $zz = unpack("dflt", $bytes); // unpack the bytes return $zz['flt']; // return the number from the associative array
The AMF UTF8 represents a string shorter than 2^16 bytes. It is composed of an Int (2 bytes) representing string length followed by the UTF8-encoded string.
The AMF LongUTF8 represents a string potentially longer than 2^16 bytes. It is composed of an LongInt (4 bytes) representing string length followed by the UTF8-encoded string.