AMFReader
The WordPress Core AMFReader class.
Defined (1)
The class is defined in the following location(s).
- /wp-includes/ID3/module.audio-video.flv.php
- class AMFReader {
- public $stream;
- public function __construct(&$stream) {
- $this->stream =& $stream;
- }
- public function readData() {
- $value = null;
- $type = $this->stream->readByte();
- switch ($type) {
- // Double
- case 0:
- $value = $this->readDouble();
- break;
- // Boolean
- case 1:
- $value = $this->readBoolean();
- break;
- // String
- case 2:
- $value = $this->readString();
- break;
- // Object
- case 3:
- $value = $this->readObject();
- break;
- // null
- case 6:
- return null;
- break;
- // Mixed array
- case 8:
- $value = $this->readMixedArray();
- break;
- // Array
- case 10:
- $value = $this->readArray();
- break;
- // Date
- case 11:
- $value = $this->readDate();
- break;
- // Long string
- case 13:
- $value = $this->readLongString();
- break;
- // XML (handled as string)
- case 15:
- $value = $this->readXML();
- break;
- // Typed object (handled as object)
- case 16:
- $value = $this->readTypedObject();
- break;
- // Long string
- default:
- $value = '(unknown or unsupported data type)';
- break;
- }
- return $value;
- }
- public function readDouble() {
- return $this->stream->readDouble();
- }
- public function readBoolean() {
- return $this->stream->readByte() == 1;
- }
- public function readString() {
- return $this->stream->readUTF();
- }
- public function readObject() {
- // Get highest numerical index - ignored
- // $highestIndex = $this->stream->readLong();
- $data = array();
- while ($key = $this->stream->readUTF()) {
- $data[$key] = $this->readData();
- }
- // Mixed array record ends with empty string (0x00 0x00) and 0x09
- if (($key == '') && ($this->stream->peekByte() == 0x09)) {
- // Consume byte
- $this->stream->readByte();
- }
- return $data;
- }
- public function readMixedArray() {
- // Get highest numerical index - ignored
- $highestIndex = $this->stream->readLong();
- $data = array();
- while ($key = $this->stream->readUTF()) {
- if (is_numeric($key)) {
- $key = (float) $key;
- }
- $data[$key] = $this->readData();
- }
- // Mixed array record ends with empty string (0x00 0x00) and 0x09
- if (($key == '') && ($this->stream->peekByte() == 0x09)) {
- // Consume byte
- $this->stream->readByte();
- }
- return $data;
- }
- public function readArray() {
- $length = $this->stream->readLong();
- $data = array();
- for ($i = 0; $i < $length; $i++) {
- $data[] = $this->readData();
- }
- return $data;
- }
- public function readDate() {
- $timestamp = $this->stream->readDouble();
- $timezone = $this->stream->readInt();
- return $timestamp;
- }
- public function readLongString() {
- return $this->stream->readLongUTF();
- }
- public function readXML() {
- return $this->stream->readLongUTF();
- }
- public function readTypedObject() {
- $className = $this->stream->readUTF();
- return $this->readObject();
- }
- }