/** * pack entity with msgpack protocol. * {@link https://github.com/msgpack/msgpack-php} * @param Entity $entity * @return string */ public function pack(Entity $entity) { if (function_exists('msgpack_pack')) { return msgpack_pack(array($entity->getTag(), $entity->getTime(), $entity->getData())); } else { return json_encode(array($entity->getTag(), $entity->getTime(), $entity->getData())); } }
public function testWhole() { $time = time(); $expected_data = array("abc" => "def"); $entity = new Entity(self::TAG, $expected_data, $time); $this->assertEquals(self::TAG, $entity->getTag(), "unexpected tag `{$entity->getTag()}` returns."); $this->assertEquals($expected_data, $entity->getData(), "unexpected data returns"); $this->assertEquals($time, $entity->getTime(), "unexpected time returns"); $entity = new Entity(self::TAG, $expected_data); $this->assertGreaterThanOrEqual($time, $entity->getTime(), "unexpected time returns"); $entity = new Entity(self::TAG, $expected_data, "not int"); $this->assertGreaterThanOrEqual($time, $entity->getTime(), "unexpected time returns"); }
public function pack(\Fluent\Logger\Entity $entity) { return serialize([$entity->getTag(), $entity->getTime(), $entity->getData()]); }