public function unpack()
{
if (!isset($this->buffer[$this->offset])) {
throw new InsufficientDataException(1, \strlen($this->buffer) - $this->offset);
}
$c = \ord($this->buffer[$this->offset]);
++$this->offset;
// fixint
if ($c <= 0x7f) {
return $c;
}
// fixstr
if ($c >= 0xa0 && $c <= 0xbf) {
return $this->unpackStr($c & 0x1f);
}
// fixarray
if ($c >= 0x90 && $c <= 0x9f) {
return $this->unpackArray($c & 0xf);
}
// fixmap
if ($c >= 0x80 && $c <= 0x8f) {
return $this->unpackMap($c & 0xf);
}
// negfixint
if ($c >= 0xe0) {
return $c - 256;
}
switch ($c) {
case 0xc0:
return null;
case 0xc2:
return false;
case 0xc3:
return true;
// MP_BIN
// MP_BIN
case 0xc4:
return $this->unpackStr($this->unpackUint8());
case 0xc5:
return $this->unpackStr($this->unpackUint16());
case 0xc6:
return $this->unpackStr($this->unpackUint32());
// MP_FLOAT
// MP_FLOAT
case 0xca:
return $this->unpackFloat32();
case 0xcb:
return $this->unpackFloat64();
// MP_UINT
// MP_UINT
case 0xcc:
return $this->unpackUint8();
case 0xcd:
return $this->unpackUint16();
case 0xce:
return $this->unpackUint32();
case 0xcf:
return $this->unpackUint64();
// MP_INT
// MP_INT
case 0xd0:
return $this->unpackInt8();
case 0xd1:
return $this->unpackInt16();
case 0xd2:
return $this->unpackInt32();
case 0xd3:
return $this->unpackInt64();
// MP_STR
// MP_STR
case 0xd9:
return $this->unpackStr($this->unpackUint8());
case 0xda:
return $this->unpackStr($this->unpackUint16());
case 0xdb:
return $this->unpackStr($this->unpackUint32());
// MP_ARRAY
// MP_ARRAY
case 0xdc:
return $this->unpackArray($this->unpackUint16());
case 0xdd:
return $this->unpackArray($this->unpackUint32());
// MP_MAP
// MP_MAP
case 0xde:
return $this->unpackMap($this->unpackUint16());
case 0xdf:
return $this->unpackMap($this->unpackUint32());
// MP_EXT
// MP_EXT
case 0xd4:
return $this->unpackExt(1);
case 0xd5:
return $this->unpackExt(2);
case 0xd6:
return $this->unpackExt(4);
case 0xd7:
return $this->unpackExt(8);
case 0xd8:
return $this->unpackExt(16);
case 0xc7:
return $this->unpackExt($this->unpackUint8());
case 0xc8:
return $this->unpackExt($this->unpackUint16());
case 0xc9:
return $this->unpackExt($this->unpackUint32());
}
throw new UnpackingFailedException(\sprintf('Unknown code: 0x%x.', $c));
}