'Uncompressed', 1 => 'ZIP', 2 => 'ZLIB', 3 => 'BZip2', ]; // IteratorAggregate interface function getIterator() { return new \ArrayIterator($this->data->packets); } // ArrayAccess interface function offsetExists($offset) { return isset($this->data[$offset]); } function offsetGet($offset) { return $this->data[$offset]; } function offsetSet($offset, $value) { return is_null($offset) ? $this->data[] = $value : $this->data[$offset] = $value; } function offsetUnset($offset) { unset($this->data[$offset]); } function body() { $body = chr($this->algorithm); switch($this->algorithm) { case 0: $body .= (string)$this->data; break; case 1: $body .= gzdeflate((string)$this->data); break; case 2: $body .= gzcompress((string)$this->data); break; case 3: $body .= bzcompress((string)$this->data); break; default: /* @todo error? */ } return $body; } function read() { $this->algorithm = ord($this->read_byte()); $this->data = $this->read_bytes($this->length); switch($this->algorithm) { case 0: $this->data = Message::parse($this->data); break; case 1: $this->data = Message::parse(gzinflate($this->data)); break; case 2: $this->data = Message::parse(gzuncompress($this->data)); break; case 3: $this->data = Message::parse(bzdecompress($this->data)); break; default: /* TODO error? */ } } }