/** * {@inheritdoc} */ public function unpack($data) { $headerSize = PackUtils::getHeaderSize($data); if (!($header = substr($data, 0, $headerSize))) { throw new Exception('Unable to unpack data.'); } $header = msgpack_unpack($header); if (!is_array($header)) { throw new Exception('Unable to unpack data.'); } $code = $header[IProto::CODE]; $body = substr($data, $headerSize); $body = msgpack_unpack($body); if ($code >= Request::TYPE_ERROR) { throw new Exception($body[IProto::ERROR], $code & Request::TYPE_ERROR - 1); } return new Response($header[IProto::SYNC], $body ? $body[IProto::DATA] : null); }
/** * @dataProvider provideHeaderData */ public function testGetHeaderSize($buffer, $expectedSize) { $this->assertSame($expectedSize, PackUtils::getHeaderSize($buffer)); }