public function testSerializer() { $version = '1'; $relayUntil = '9999999'; $expiration = '9898989'; $id = '123'; $cancel = '0'; $minVer = '0'; $maxVer = '0'; $priority = '50'; $comment = new Buffer('comment'); $statusBar = new Buffer('statusBar'); $setCancel = [1, 2]; $setSubVer = [50, 99]; $detail = new AlertDetail($version, $relayUntil, $expiration, $id, $cancel, $minVer, $maxVer, $priority, $comment, $statusBar, $setCancel, $setSubVer); $serializer = new AlertDetailSerializer(); $serialized = $detail->getBuffer(); $parsed = $serializer->parse($serialized); $this->assertEquals($detail, $parsed); }
/** * @param AlertDetail $detail * @return \BitWasp\Buffertools\Buffer */ public function serialize(AlertDetail $detail) { $setCancels = []; foreach ($detail->getSetCancel() as $toCancel) { $t = new Parser(); $setCancels[] = $t->writeBytes(4, Buffer::int($toCancel), true)->getBuffer(); } $setSubVers = []; foreach ($detail->getSetSubVer() as $subVer) { $t = new Parser(); $setSubVers[] = $t->writeBytes(4, Buffer::int($subVer), true)->getBuffer(); } return $this->getTemplate()->write([$detail->getVersion(), $detail->getRelayUntil(), $detail->getExpiration(), $detail->getId(), $detail->getCancel(), $setCancels, $detail->getMinVer(), $detail->getMaxVer(), $setSubVers, $detail->getPriority(), $detail->getComment(), $detail->getStatusBar()]); }